【发布时间】:2012-03-21 20:36:36
【问题描述】:
我正在尝试更新网格视图,以便一旦从中删除一行,它将刷新并且不再自动显示该行。但是,这似乎不起作用。
到目前为止我已经尝试过:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional" >
<ContentTemplate>
<asp:GridView ID="BookingsGridView" runat="server" AutoGenerateColumns="False"
BorderColor="ForestGreen" BorderStyle="Ridge" BorderWidth="10px"
CellPadding="4" ForeColor="#333333" GridLines="None"
onrowdatabound="dgTest_RowDataBound" OnSelectedIndexChanged="Cancel_Booking">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowSelectButton="true" SelectImageUrl="~/Images/Icons/Cross.png" SelectText="Cancel"/>
<asp:BoundField DataField="Book_id" HeaderText="Book_id"/>
<asp:BoundField DataField="Username" HeaderText="Username" />
<asp:BoundField DataField="Client" HeaderText="Client" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:BoundField DataField="BookingDate" HeaderText="BookingDate" />
<asp:BoundField DataField="Duration" HeaderText="Duration" />
<asp:BoundField DataField="Location" HeaderText="Location" />
<asp:BoundField DataField="Payment" HeaderText="Payment" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#546E96" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333"/>
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
</asp:GridView>
<br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="BookingsGridView" />
</Triggers>
</asp:UpdatePanel>
然后我打电话给
UpdatePanel1.Update();
一旦成功删除该行。
为什么这不起作用?
【问题讨论】:
-
您是从 GridView 控件、数据绑定到 GridView 或从其他位置(如数据库)中删除该行吗?
-
是的,它们存储在数据库中,gridview 显示这些结果。因此,当我删除某些内容时,我会将其从数据库中删除,并希望 Gridview 更新以显示数据库结果。
-
在调用
UpdatePanel1.Update()之前是否要重新绑定网格? -
处理删除后使用 Gridview.binddata()..
标签: c# asp.net ajax gridview updatepanel