PageIndex更改但数据保持不变

时间:2017-06-27 23:57:32

标签: c# asp.net list gridview edmx

我有一个GridView我将列表绑定到通过edmx检索的数据。我的问题是,当我点击寻呼机,页面发生变化,我已经调试并知道它正在改变值,但它总是只显示第一页的数据。我错过了什么?哦,我在LoadAllRequestsData()中从Page_Load致电if(!Page.IsPostBack)

<cm:GridControl runat="server" ID="gvAllRequests" DataKeyNames="Number" OnPageIndexChanging="AllRequestsGridViewPageIndexChanging" ShowHeaderWhenEmpty="True" EmptyDataText="No requests to show." >
                                    <Columns>
                                        <asp:BoundField DataField="Number" HeaderText="Number" SortExpression="Number" InsertVisible="False" ReadOnly="True"></asp:BoundField>
                                        <asp:BoundField DataField="CustomerId" HeaderText="CustomerId" SortExpression="CustomerId" Visible="False"></asp:BoundField>
                                        <asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer" Visible="False"></asp:BoundField>
                                        <asp:BoundField DataField="TypeId" HeaderText="TypeId" SortExpression="TypeId" Visible="False"/>
                                        <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type"></asp:BoundField>
                                        <asp:BoundField DataField="Note" HeaderText="Note" SortExpression="Note"/>
                                        <asp:BoundField DataField="RequestedOn" HeaderText="Requested On" SortExpression="RequestedOn"/>
                                        <asp:BoundField DataField="RequestedById" HeaderText="RequestedById" SortExpression="RequestedById" Visible="False" />
                                        <asp:BoundField DataField="RequestedBy" HeaderText="Requested By" SortExpression="RequestedBy" />
                                        <asp:BoundField DataField="CompletedOn" HeaderText="Completed On" SortExpression="CompletedOn" />
                                        <asp:BoundField DataField="CompletedById" HeaderText="CompletedById" SortExpression="CompletedById" Visible="False"/>
                                        <asp:BoundField DataField="CompletedBy" HeaderText="Completed By" SortExpression="CompletedBy" />
                                        <asp:BoundField DataField="LastModifiedOn" HeaderText="LastModified On" SortExpression="LastModifiedOn" />
                                        <asp:BoundField DataField="LastModifiedById" HeaderText="LastModifiedById" SortExpression="LastModifiedById" Visible="False"/>
                                        <asp:BoundField DataField="LastModifiedBy" HeaderText="LastModified By" SortExpression="LastModifiedBy" />
                                        <asp:CheckBoxField DataField="IsDeleted" HeaderText="IsDeleted" SortExpression="IsDeleted" Visible="False"/>
                                    </Columns>
                                </cm:GridControl>




private void LoadAllRequestsData(string sortExpression = "RequestedOn", SortDirection sortDirection = SortDirection.Descending)
    {
          var db = new CrewManagerEntities();

          var list = db.GetAllRequestsByUserId(_customerId).ToList();

          if (!string.IsNullOrEmpty(sortExpression))
          {
              list = list.AsQueryable().OrderBy(sortExpression + " " + (sortDirection == SortDirection.Ascending ? "ASC" : "DESC")).ToList();
              gvAllRequests.SetSort(sortExpression, sortDirection);
          }

          gvAllRequests.DataSource = list;

          gvAllRequests.DataBind();
    }

    protected void AllRequestsGridViewPageIndexChanging(object sender, GridViewPageEventArgs e)
    {
          gvAllRequests.PageIndex = e.NewPageIndex;
          LoadAllRequestsData();
    }

编辑:所以,我尝试使用SqlDataSource而不是在代码隐藏中进行调用并使用列表并且分页工作。这很好,但我想知道为什么列表不起作用,因为可能存在我需要使用列表源的情况。有什么想法吗?

0 个答案:

没有答案