1

I can't get the Gridview in the Updatepanel to refresh after I've made changes. can someone help? I'm using rowCommand for Delete Row in GridView . I'm using the ToolkitScriptManager control and the 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();

        }
    }
user3197356
  • 11
  • 1
  • 3

1 Answers1

5

The command name "Delete" is recognized by the data-bound control and its raising multiple events that may be getting in your way. https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.buttonfield.commandname%28v=vs.110%29.aspx

Since you are handling the deletion directly on gridview commmand handler, I would try to give a different command name like DeleteRow

KiH
  • 101
  • 1
  • 4