最近两天我遇到了一个奇怪的问题。在 UpdatePanel 中使用时,我的 gridview 的 rowcommand 事件会触发两次。如果我在更新面板之外使用它。它按预期工作。谁能指导我如何解决这个问题。
我的示例代码如下:ASPX
<asp:UpdatePanel ID="upDescription2" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigge`enter code here`r ControlID="ddlDescription1" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:DropDownList ID="ddlDescription2" runat="server" Width="70%" AutoPostBack="True" OnSelectedIndexChanged="ddlDescription2_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upGrdView" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlDescription2" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="grdView" runat="server" CssClass="grd" AutoGenerateColumns="False"
OnRowCommand="grdView_RowCommand" OnRowDataBound="grdView_RowDataBound">
<Columns>
<asp:ImageButton ID="btnRemove" runat="server" CommandName="remove"/>
Blah Column
Blah Column
Blah Column
Blah Column
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
C#:
protected void ddlDescription2_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
}
protected void grdView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Remove"))
{
RemoveRow(e.CommandArgument);
}
}
问候乌斯曼·哈立德