加速Asp.net gridview数据绑定

时间:2015-03-24 17:11:45

标签: c# asp.net twitter-bootstrap updatepanel

我有一个ASP.net gridview,其中应用了bootstrap 3样式,并且它位于Update面板中。绑定网格时加载需要一分多钟,但实际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>

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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