Forums » .NET » ASP.NET »

ASP.NET2.0 Gridview sorting sample code


Posted Date: 11 Nov 2008      Posted By:: Hari     Member Level: Silver    Member Rank: 2200     Points: 1   Responses: 3



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.





Responses

#315403    Author: Prashant Jadhav      Member Level: Silver      Member Rank: 3042     Date: 11/Nov/2008   Rating:     Points: -20

[Response removed by Admin for invalid response to the thread or violation of forum policies.]

 
#315407    Author: Yousuf      Member Level: Silver      Member Rank: 0     Date: 11/Nov/2008   Rating:     Points: -20

[Response removed by Admin for invalid response to the thread or violation of forum policies.]

 
#342405    Author: dotnet programmer      Member Level: Gold      Member Rank: 902     Date: 02/Feb/2009   Rating: 2 out of 52 out of 5     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
}





 
Post Reply

 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.



Return to Discussion Forum
Start new thread

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India