Link to home
Start Free TrialLog in
Avatar of Srinivas Mantha
Srinivas ManthaFlag for India

asked on

Sort on Ascending order of transformed field in LINQ with ASP.NET c#

I  am  populating a dropdown list with a transformed field for datatextfield with a transformed field generated after using LINQ with ASP.NET C# for a web application.  The transformed field is generated from the original database field.  The sort order is different in the original database field as opposed to transformed field. I want ascending order of the  transformed field in the dropdown list

Partial required code is as follows

 

if (dsSupp.Tables[0].Rows.Count > 0)

             {

                 var varSuppliers = from dtSupp in dsSupp.Tables[0].AsEnumerable()

                                     select new

                                    {

                                        aidsup = dtSupp.Field<Int32>("aidsup"),

                                        fullname = newdata ; // new string data results from an algorithm to transform of //original text filed (varchar) sname in the database                                    }; 

                 ddlsuppliers.DataSource = varSuppliers;

                 ddlsuppliers.DataValueField = "aidsup";

                 ddlsuppliers.DataTextField = "fullname";

                 ddlsuppliers.DataBind();

             }

I want sort in ascending order of the transformed field 'fullname' not on sname

ASKER CERTIFIED SOLUTION
Avatar of Dorababu M
Dorababu M
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Srinivas Mantha

ASKER

Of the two, the following one is working sorting the dropdown list correctly, although the first one should also work.
ddlsuppliers.DataSource = varSuppliers.OrderBy(s => s.fullname); 
Glad it works for you :)