Hello Dinesh,
You need to add the OnSorting="GridView1_Sorting"
OnRowDataBound=" GridView1_RowDataBound"
Add the below code:
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
//here dsUsers is the SqlDataSource ID for Binding the GridView
GridView1.DataSourceID = "dsUsers";
GridView1.DataBind();
}
Add the below code in RowDataBound for sorting:
protected void gvCust_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridView gridView = (GridView)sender;
if (gridView.SortExpression.Length > 0)
{
int cellIndex = -1;
foreach (DataControlField field in gridView.Columns)
{
if (field.SortExpression == gridView.SortExpression)
{
cellIndex = gridView.Columns.IndexOf(field);
break;
}
}
if (cellIndex > -1)
{
if (e.Row.RowType == DataControlRowType.Header)
{
// this is a header row,
// set the sort style
e.Row.Cells[cellIndex].CssClass +=
(gridView.SortDirection == SortDirection.Ascending
? " sortasc" : " sortdesc");
}
}
}
}