在updatepanel中按RowCommand删除行后,gridview不会更新

时间:2014-11-07 06:36:10

标签: gridview updatepanel rowcommand

在我做出更改后,我无法在Updatepanel中获取Gridview。有人可以帮忙吗? 我在GridView中使用rowCommand for Delete Row。 我正在使用ToolkitScriptManager控件和UpdatePanel。

  <asp:UpdatePanel runat="server" ID="upt1">
    <ContentTemplate>
        <asp:GridView ID="gwSubG1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" Width="600px" OnSelectedIndexChanged="gwSubG1_SelectedIndexChanged" DataKeyNames="One_Grop_Id" OnRowCommand="gwSubG1_RowCommand" OnRowDeleting="gwSubG1_RowDeleting">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:BoundField DataField="Grop_Name" HeaderText="Group One" ItemStyle-HorizontalAlign="Center" HeaderStyle-CssClass="HeaderCenter">
                    <HeaderStyle CssClass="HeaderCenter" />
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="ORG_Grp_Nam" HeaderText="Main Group" ItemStyle-HorizontalAlign="Center" HeaderStyle-CssClass="HeaderCenter">
                    <HeaderStyle CssClass="HeaderCenter" />
                    <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:ImageButton ID="btnDelete" ImageUrl="~/Theme/Icon/info.png" CausesValidation="false" runat="server" CommandArgument='<%# Eval("One_Grop_Id") %>' CommandName="Delete" AlternateText="Delete" OnClientClick="return confirm('are you sure?');" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

    </ContentTemplate>
</asp:UpdatePanel>

mycode的:

        protected void gwSubG1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "Delete")
        {
            DB.strQuery = "DELETE FROM [Sub_Grop_One] WHERE One_Grop_Id=@id";
            DB.cmd = new SqlCommand(DB.strQuery, DB.MyConnection);
            DB.cmd.Parameters.AddWithValue("id", e.CommandArgument.ToString());
            DB.MyConnection.Open();
            DB.cmd.ExecuteNonQuery();
            DB.MyConnection.Close();

            FillGW();

            this.gwSubG1.DataBind();

            upt1.Update();

        }
    }

1 个答案:

答案 0 :(得分:4)

命令名称&#34;删除&#34;被数据绑定控件识别并提升可能妨碍您的多个事件。 https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.buttonfield.commandname%28v=vs.110%29.aspx

由于您直接在gridview commmand处理程序上处理删除,我会尝试提供不同的命令名称,如DeleteRow