Subscribe to Subscribers

Online Members

ankita
More...

Forums » .NET » ASP.NET »

ASP.NET2.0 Gridview sorting sample code


Posted Date: 11 Nov 2008      Posted By:: Hari     Member Level: Silver    Member Rank: 2104     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: 2933     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: 882     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.



Next : THREAD
Previous : Vijay see this
Return to Discussion Forum
Post New Message
Category:

Related Messages

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.