加速 Asp.net gridview 数据绑定

Speed up Asp.net gridview databind

我有一个 ASP.net gridview,应用了 bootstrap 3 种样式,它位于更新面板中。当我绑定网格时,加载需要一分多钟,但实际 SP 仅需 3 秒即可加载数据。有什么办法可以加快数据绑定

C#

DataSet ds = GetSearchResults(grdattendee_search.PageIndex);
Session["attendee"] = ds.Tables[0];
grdattendee_search.DataSource = ds.Tables[0];
grdattendee_search.DataBind();


protected void grdattendee_search_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    grdattendee_search.PageIndex = e.NewPageIndex;
    if (Session["attendee"] != null)
    {
        grdattendee_search.DataSource = Session["attendee"];
        grdattendee_search.DataBind();
    }
    else
    bindgrid();
}

Aspx

<asp:GridView ID="grdattendee_search" runat="server" AllowPaging="true" PageSize="10"
                        AutoGenerateColumns="false" CssClass="table table-hover" DataKeyNames="ID"
                        GridLines="Horizontal" BorderStyle="None" PagerStyle-CssClass="bs-pagination"
                        OnRowCommand="grdattendee_search_RowCommand" OnPageIndexChanging="grdattendee_search_PageIndexChanging">
                        <Columns>
                            <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID"
                                Visible="false" />
                            <asp:TemplateField HeaderText="Name" SortExpression="Name">
                                <ItemTemplate>
                                    <%-- <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("Name")%>'></asp:HyperLink>--%>
                                    <asp:LinkButton ID="btn" runat="server" CommandName="select" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
                                        Text='<%# string.Concat(Eval("name_first"), " ", Eval("name_last"))%>'></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="Degree" HeaderText="Degree" SortExpression="Degree" />
                            <asp:BoundField DataField="specialty" HeaderText="Specialty" SortExpression="specialty" />
                            <asp:BoundField DataField="city" HeaderText="City" SortExpression="city" />
                            <asp:BoundField DataField="state" HeaderText="State" SortExpression="state" />
                        </Columns>
                    </asp:GridView>

如果您不使用编辑或删除命令,那么您可以创建 TempleteField 和直接 Eval your DataMemeber 项模板而不是 DataBound 字段。这将有助于更快的绑定。

确定了问题。问题不在于绑定。页面加载中的另一个进程正在阻止当前数据绑定。