gpt4 book ai didi

c# - 使用 UpdatePanel 删除行后更新/刷新 Gridview。 ASP.NET C# AJAX

转载 作者:太空宇宙 更新时间:2023-11-03 16:33:59 32 4
gpt4 key购买 nike

我正在尝试更新 gridview,以便一旦从中删除了一行,它就会刷新并且不再自动显示该行。然而,这似乎不起作用。

到目前为止我已经尝试过:

    <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();

删除行成功

为什么这不起作用?

最佳答案

如果您有将数据从数据库绑定(bind)到 datagridview 的 Read 方法,只需在您的 delete 方法上再次绑定(bind)它。

像这样:

private void Read()
{
///binding stuff datagridview.datasource = datasource;
}


private void Delete()
{

//Your delete stuff

//call

Read(); // this will refresh your grid after deleting a record.

}

最好的问候

关于c# - 使用 UpdatePanel 删除行后更新/刷新 Gridview。 ASP.NET C# AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9812415/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com