0
我在過去的2天中遇到了一個奇怪的問題。在UpdatePanel中使用時,我的gridview的rowcommand事件觸發兩次。如果我在更新面板外使用它。它按預期工作。任何人都可以指導我如何解決這個問題。GridView RowCommand事件在UpdatePanel中觸發兩次
我的樣本代碼如下: 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);
}
}
問候 烏斯曼·哈立德