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" };

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.