ASP.NET GridView 在异步回发后丢失了 jquery 数据表格式

问题描述 投票:0回答:1

当我单击 GridView 内的按钮时,我有一个 asp.net GridView 转换为 jquery 数据表,丢失了数据表格式并在控制台中抛出错误

这是源代码中的GridView:

<!-- GridView -->
    <asp:UpdatePanel runat="server" ID="pnlGrid" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:GridView ID="gvMovies" runat="server" AutoGenerateColumns="False" CssClass="table table-bordered myTable" EmptyDataText="No data found !"
                OnRowCommand="gvMovies_RowCommand" AllowPaging="true" PageSize="5" OnPageIndexChanging="gvMovies_PageIndexChanging"
                OnRowDataBound="gvMovies_RowDataBound">
                <HeaderStyle CssClass="thead-dark text-center" />
                <Columns>
                    <asp:BoundField DataField="Id" HeaderText="Référence" HeaderStyle-CssClass="d-none" ItemStyle-CssClass="d-none" />
                    <asp:BoundField DataField="Title" HeaderText="Title" />
                    <asp:BoundField DataField="Genre" HeaderText="Genre" />
                    <asp:BoundField DataField="Year" HeaderText="Year" />
                    <asp:BoundField DataField="Rate" HeaderText="Rate" />
                    <asp:TemplateField HeaderText="Actions" ItemStyle-CssClass="text-center">
                        <ItemTemplate>
                            <!-- View button with icon -->
                            <asp:LinkButton runat="server" ID="btnView" CssClass="btn btn-info btn-sm btn-view"
                                CommandName="btnView"
                                CommandArgument='<%# Eval("Id") %>'>
                                <i class="bi bi-eye-fill text-white"></i>
                            </asp:LinkButton>
                            <!-- Edit button with icon -->
                            <asp:LinkButton runat="server" ID="btnEdit" CssClass="btn btn-warning btn-sm" ClientIDMode="Static" EnableViewState="true" ViewStateMode="Enabled" CommandName="btnEdit" CommandArgument='<%# Eval("Id") %>'>
                                <i class="bi bi-pencil-fill text-white"></i>
                            </asp:LinkButton>
                            <!-- Delete button with icon -->
                            <asp:LinkButton runat="server" ID="btnDelete" CssClass="btn btn-danger btn-sm" CommandName="btnDelete" CommandArgument='<%# Eval("Id") %>'>
                                <i class="bi bi-trash-fill text-white"></i>
                            </asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>
c# asp.net gridview datatables
1个回答
0
投票

在绑定 gridview 后和每个回发事件时使用此代码。

if (gvMovies.Rows.Count > 0)
{
    gvMovies.HeaderRow.TableSection = TableRowSection.TableHeader;
    gvMovies.UseAccessibleHeader = true;
}

这应该可以解决你的问题。

© www.soinside.com 2019 - 2024. All rights reserved.