My previous post explains how to convert a column to row in JavaScript array. In this post, we will do the same thing but with C# Array and DataTable using the power of LINQ or Lambda expression. For simplicity, I am using the same data.
Tag: linq
An Interesting LINQ Exercise
This post is in reply of this thread of the official ASP.NET forum.
The input data is in following format:
S.no | Name | wages |
---|---|---|
1 | Tom | $200 |
1 | Tom | $300 |
1 | Tom | $400 |
2 | Rob | $500 |
2 | Rob | $600 |
C# LINQ: Saving JSON Data to SQL Server Database using JSON.NET and SqlBulkCopy
In this post, we will add JSON data to Sql Server tables using ASP.NET Web API, JSON.NET and SqlBulkCopy. The data is posted using jQuery ajax to web api which accepts JObject type argument, parse data, arrange data in the required table structure and save to database. Here is the structure of JSON and SQL Server tables.
C# LINQ: Combine Multiple Sequences In Parallel
In this article, we will see how to join multiple arrays, lists or collections by order with LINQ. In other words, we can say Zip operation on multiple sequences. Assuming we have following arrays:
int[] numbers = { 1, 2, 3 }; string[] abc = { "a", "b", "c" }; string[] pqr = { "p", "q", "r" }; string[] xyz = { "x", "y", "z" }; string[] words = { "one", "two", "three" };
Implementing Role Based Menu in ASP.NET MVC 4
In my previous post, I explained how to implement custom role provider, authorization and role based navigation on successful login in asp.net mvc 4. In this post, We’ll implement role based menu.
Anonymous Type LINQ Result and GridView Sorting in ASP.NET
It explains how to implement asp.net gridview sorting functionality when gridview datasource is Anonymous Type. Suppose you are using Entity Framework OR LINQ to sql, getting data with a particular structure having different columns from different tables (Anonymous Type) using LINQ and you have defined it as a datasource of gridview. It’s okay to display data. Now, you have to implement sorting feature. One way is to convert Anonymous Type to Datatable and sort it defaultview, but it’s too complex. You might have tasted dynamic sorting with extension method as mentioned here and here but not useful for Anonymous type. Another way is to use switch case for sortexpression and use OrderBy and OrderByDescending for each column. It’s not a generalize solution. then what….???
Displaying Total in ASP.NET Gridview Footer Row Without using Template Field
There are tons of articles to display total in asp.net gridview footer row. The common approach to implement this is:
1. Create template field of the column which is to be totalled.
2. Define FooterTemplate and add Label control.
3. Take a variable and add value of each row in GridView1_RowDataBound event.
4. Find label control in footer and assign the variable.
It’s too complex. Let’s see how to take advantage of LINQ or Lambda expression and skip these steps.
Sequence contains no elements : LINQ error
If you are using LINQ or Lambda expression and getting error: InvalidOperationException “Sequence contains no elements”. It means you are trying to retrieve an element from an empty sequence(may be returned by LINQ query). There are some basic rules to handle this in LINQ or lambda expression.
Bind array to specific column of asp.net gridview
The object is to bind an array to particular column of asp.net gridview. Suppose we have a grid having 3 columns and an array say “data“. Now we have to bind data array to grid’s second column (binded by mycolumn). See following html code:
Get Selected Radio button’s Text in C# windows app
The object is to get selected radio button’s text in windows app using C#. It can be done in many ways. Suppose you have one group box having radio-buttons. You have to show selected radio button’s text on OK button click.