I found the following event that I want to use in my asp.net app.
private void grid_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
try
{
if (e.RowIndex1 == this.dataGridView1.Rows.Count -1)
e.Handled = true;
if (e.RowIndex2 == this.dataGridView1.Rows.Count - 1)
e.Handled = true;
return;
}
catch (Exception ex)
{
ex.ToString();
}
}
Basically it checks to see i开发者_Go百科f it is the last row and if it is it does not sort. Hence sorting all rows besides the last one.
How can I implement this into my asp.net page in which I have a GridView. This event was written for C# desktop apps and I cannot seem to find the equivalent for asp.net
Thanks!
First, add the "OnSorting" event to your GridView tag in the aspx markup:
<asp:GridView ID="gridView" OnSorting="gridView_Sorting" runat="server" />
Then implement gridview_Sorting()
protected void gridView_Sorting(object sender, GridViewSortEventArgs e)
{
//Perform manual sort as you have described
}
Yes, you do not have the row by row sort checks/convenience... rather you must override and perform your own sort method. This is one of the many limitations of the web vs desktop components as far as I know.
In ASP .net the grid view has template fields. You can make your last row into a template footer, to make a Total row for example. Using this method you will still be able to sort, but your total row will stay at the bottom.
http://msdn.microsoft.com/en-us/library/bb288032.aspx
精彩评论