2

次のような UpdatePanel に GridView があります。

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" GridLines="None"
            AllowPaging="True" OnRowCommand="GridViewAllProducts_RowCommand">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <img id="imgImage" src='<%# Bind("Image") %>' class="imgNewsAllNewsUC noBorder" alt=""
                            runat="server" />
                        <asp:ImageButton ID="ibDelete" CommandName="delete" CommandArgument='<%# Bind("Id") %>'
                            runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>

コードビハインドは次のようになります。

protected void GridViewAllProducts_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "delete")
    {
        new ProductC().DeleteBy_Id(Convert.ToInt32(e.CommandArgument));

        GridViewAllProducts.DataSource = new ProductC().GetAllProducts();
        GridViewAllProducts.DataBind();
    }
}

ibDelete をクリックすると、関連する行がデータベースから削除されますが、ページを更新するまでページは変更されません。どこが間違っていますか?

4

1 に答える 1

2
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    ....
</asp:UpdatePanel>

protected void GridViewAllProducts_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "delete")
    {
        new ProductC().DeleteBy_Id(Convert.ToInt32(e.CommandArgument));

        GridViewAllProducts.DataSource = new ProductC().GetAllProducts();
        GridViewAllProducts.DataBind();
        UpdatePanel1.Update();
    }
}
于 2013-01-03T14:17:06.083 に答える