I think the best solution is to add two parameters in the stored procedure,one for the column(field) name and the other one specify whether sorting is ASC/DESC.
If you don't want to do this, then you can add these lines in your code behind.
DataTable dTablePropertyList = new DataTable(); // declaring new datatable
//setting cloumn name and datatype
foreach(DataColumn dColumnProperty in dSetPropertyList.Tables[0].Columns)
{
if(dColumnProperty.ColumnName.ToString().Trim().To Upper() == "VIEWEDCOUNT")
{
dTablePropertyList.Columns.Add(dColumnProperty.Col umnName,System.Type.GetType("System.Int32"));
}
else
{
dTablePropertyList.Columns.Add(dColumnProperty.Col umnName,dColumnProperty.DataType);
}
}
//adding rows to datatable
foreach(DataRow dRowPropertyin dTablePropertyList.Tables[0].Rows )
{
DataRow dRow = dTablePropertyList.NewRow();
dRow[0] = dRowProperty[0];
dRow[1] = dRowProperty[1];
dRow[2] = dRowProperty[2];
dRow[3] = dRowProperty[3];
dRow[4] = dRowProperty[4];
dRow[5] = dRowProperty[5];
dRow[6] = dRowProperty[6];
dTablePropertyList.Rows.Add(dRow);
}
DataView dViewPropertyList = new DataView(dTablePropertyList);
//
dViewPropertyList.Sort=Session["sortExpProperty"] + " " + Session["sortExpPropertyOrder"];
dGridProperty.DataSource = dViewPropertyList ;
dGridProperty.DataBind();
hope this will help:)
|