我有一个gridview,我正在尝试对列进行排序。当我这样做时,它会引发“ StackOverflow”异常
aspx代码:
<asp:GridView ID="grdItems" runat="server" Width="100%" AllowPaging="True"
CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" OnRowDataBound="grdItems_RowDataBound" AllowSorting="True" OnSorting="grdItems_Sorting">
<FooterStyle BackColor="White" Font-Bold="True" ForeColor="#808080"/>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<pagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" Font-Size="Small" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="actionItemId" HeaderText="Item Id" SortExpression="actionItemId" >
<ItemStyle Font-Size="Small" VerticalAlign="Top" />
<HeaderStyle Font-Bold="True" Font-Size="Small" HorizontalAlign="Left" Width="65px"/>
<FooterStyle Font-Size="12px" />
</asp:BoundField>
<asp:BoundField DataField="dueDate" DataFormatString="{0:d}" HeaderText="Due By" HtmlEncode="False" >
<ItemStyle Font-Size="Small" VerticalAlign="Top" />
<HeaderStyle Font-Size="Small" HorizontalAlign="Left" Width="65px" />
</asp:BoundField>
</Columns>
<pagerSettings Mode="NumericFirstLast" />
</asp:GridView>
后面的代码:
Protected Sub grdItems_Sorting(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles grdItems.Sorting
Dim sortExpression As String = e.SortExpression
ViewState("SortExpression") = sortExpression
If grdItems.SortDirection = WebControls.SortDirection.Ascending Then
grdItems.Sort(sortExpression, WebControls.SortDirection.Descending)
Else
grdItems.Sort(sortExpression, WebControls.SortDirection.Ascending)
End If
End Sub
现在,我知道了,因为我在Sorting事件处理程序中使用Sort(),所以抛出了该异常。还有其他解决方法吗?任何帮助将不胜感激。谢谢!