Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a datatable How can I can I get SortExpression of Datatable
Exmple Like

C#
DataTable data = objAllDetail.Search();


How can I get SortExpression of data please help

Thanks
Posted
Updated 29-Oct-12 0:35am
v2
Comments
vivektiwari97701 29-Oct-12 7:10am    
ur qstn is not clear ...can u explain more
i.e.
what type of object objAllDetail is??

Use following expression

C#
Datatable.DefaultView.Sort = "ColumnToSortOn ASC"; 


Hope that helps.
-Milind
 
Share this answer
 
Try something like this,
C#
void Sort_Grid(Object sender, DataGridSortCommandEventArgs e)
      {
         // Retrieve the data source from session state.
         DataTable dt = (DataTable)Session["Source"];

         // Create a DataView from the DataTable.
         DataView dv = new DataView(dt);

         // The DataView provides an easy way to sort. Simply set the 
         // Sort property with the name of the field to sort by.
         dv.Sort = e.SortExpression;

         // Re-bind the data source and specify that it should be sorted
         // by the field specified in the SortExpression property.
         ItemsGrid.DataSource = dv;
         ItemsGrid.DataBind();
      }


Source [^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900