我在 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 时,相关行将从数据库中删除,但在我刷新页面之前页面不会更改。我哪里错了?