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
ddlsuppliers.DataSource = varSuppliers.OrderBy(s => s.fullname);