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