我有一个简单的asp.net gridview,其中AllowSorting设置为true。这是我在其他网页中多次使用的代码,没有任何问题。
在这种情况下,当我单击希望进行排序的列标题时,我什么也没得到。我在事件方法中设置了一个断点,但从未达到过该断点。我检查了属性事件,并正确设置了onSorting事件。我看不到任何明显的错误,其他任何人以前都遇到过这个问题吗?
<asp:GridView ID="inputGrid" AutoGenerateColumns="False" runat="server" CellPadding="5" OnRowCommand="inputGrid_RowCommand"
AllowSorting="True" AllowPaging="false" PageSize="20" OnSorting="inputGrid_Sorting3"
OnPageIndexChanging="inputGrid_PageIndexChanging" AlternatingRowStyle-BackColor="LightBlue" PagerSettings-Position="Top" PageIndex="0">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="Select"
AutoPostBack="false"
Text=""
TextAlign="Right"
OnCheckedChanged="Select_CheckedChanged"
runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="UpdateButton" runat="server" Font-Bold
CommandName="UpdateField"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
Text="Edit" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField
HeaderText="Error"
SortExpression="errorMsg"
DataField="errorMsg" />
<asp:BoundField
HeaderText="Vendor Number"
SortExpression="controlVendorNbr"
DataField="controlVendorNbr" />
<asp:BoundField
HeaderText="Vendor Suffix"
SortExpression="controlVendorSuffix"
DataField="controlVendorSuffix" />
<asp:BoundField
HeaderText="Vendor Name"
SortExpression="controlVendorName"
DataField="controlVendorName" />
<asp:BoundField
HeaderText="Vendor Type"
SortExpression="controlVendorType"
DataField="controlVendorType" />
<asp:BoundField
HeaderText="Address"
SortExpression="controlVendorAddr1"
DataField="controlVendorAddr1" />
<asp:BoundField
HeaderText="City"
SortExpression="controlVendorCity"
DataField="controlVendorCity" />
<asp:BoundField
HeaderText="State"
SortExpression="controlVendorState"
DataField="controlVendorState" />
<asp:BoundField
HeaderText="Zip Code"
SortExpression="controlVendorZip"
DataField="controlVendorZip" />
<asp:BoundField
HeaderText="Status"
SortExpression="controlVendorStatus"
DataField="controlVendorStatus" />
<asp:BoundField
HeaderText="Vendor Number"
SortExpression="sxeVendorNbr"
DataField="sxeVendorNbr" />
<asp:BoundField
HeaderText="Vendor Ship From"
SortExpression="sxeVendorSequence"
DataField="sxeVendorSequence" />
<asp:BoundField
HeaderText="Vendor Name"
SortExpression="sxeVendorName"
DataField="sxeVendorName" />
<asp:BoundField
HeaderText="Vendor Type"
SortExpression="sxeVendorType"
DataField="sxeVendorType" />
<asp:BoundField
HeaderText="Address"
SortExpression="sxeVendorAddr1"
DataField="sxeVendorAddr1" />
<asp:BoundField
HeaderText="City"
SortExpression="sxeVendorCity"
DataField="sxeVendorCity" />
<asp:BoundField
HeaderText="State"
SortExpression="sxeVendorState"
DataField="sxeVendorState" />
<asp:BoundField
HeaderText="Zip Code"
SortExpression="sxeVendorZip"
DataField="sxeVendorZip" />
<asp:BoundField
HeaderText="Status"
SortExpression="sxeVendorStatus"
DataField="sxeVendorStatus" />
<asp:BoundField
HeaderText="Created Date"
SortExpression="createDate"
DataField="createDate" />
<asp:BoundField
HeaderText="Last Updated Date"
SortExpression="lastUpdatedDate"
DataField="lastUpdatedDate" />
<asp:BoundField
HeaderText="User"
SortExpression="lastUser"
DataField="lastUser" />
<asp:BoundField
HeaderText="Database Row Id"
Visible="true"
SortExpression="dbRowId"
DataField="dbRowId" />
<asp:BoundField
HeaderText="rowId"
DataField="rowId" />
<asp:BoundField
HeaderText="Comment"
Visible="true"
SortExpression="comment"
DataField="comment" />
</Columns>
</asp:GridView>
protected void inputGrid_Sorting3(object sender, GridViewSortEventArgs e)
{
}
当我在inputGrid_Sorting3方法的顶部括号中设置一个断点时,当我单击可排序列a之一顶部的标题时,我再也找不到它。
答案 0 :(得分:0)
好的,这就是问题所在。当您单击标题以对列进行排序时,首先到达代码页中的row命令方法,然后再到达sort方法。行命令代码被炸断并停止流向sort方法。我不知道在尝试对网格进行排序时会触发行命令事件。我暂时从.aspx页面中取出了更新面板代码,然后看到调试转到了行命令方法而不是sort方法。我在行命令方法代码周围放置了一个“ if”条件,以便它可以传递到sort方法。现在可以了。