You must Sign In to post a response.

ASP.NET2.0 Gridview sorting sample code

Hi Viewers,

I am new to ASP.NET(2.0) i want to write the code for gridview sorting.
Please let me know the sample code.


Comments

#315403    Author: Prashant Jadhav    11 Nov 2008 Member Level: Silver   Points : -20

[Response removed by Admin. Read forum policies.]

#315407    Author: Yousuf  11 Nov 2008 Member Level: Silver   Points : -20

[Response removed by Admin. Read forum policies.]

#342405    Author: dotnet programmer  02 Feb 2009 Member Level: Gold   Points : 4

protected void gvSorting_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dtSortTable = gvSorting.DataSource as DataTable;

if (dtSortTable != null)
{
DataView dvSortedView = new DataView(dtSortTable);
dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection);

gvSorting.DataSource = dvSortedView;
gvSorting.DataBind();
}
}

private string getSortDirectionString(SortDirection sortDireciton)
{
string newSortDirection = String.Empty;
if(sortDirection== SortDirection.Ascending)
{
newSortDirection = "ASC";
}
else
{
newSortDirection = "DESC";
}

return newSortDirection
}


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.