我有一个问题,理论上应该很简单,但我现在花了3个小时才弄明白。我有一个gridview和lingdatasource,我尝试实现自定义分页。无论我做什么,我似乎都被困在25页的大小!代码如下 谢谢!
<asp:GridView ID="gvCustomerList" SkinID="StandardGridView" AutoGenerateColumns="false" DataSourceID="LqCustomerSource"
AllowPaging="false" AllowSorting="false" PageSize="50" runat="server" OnSorting="gvCustomerList_OnSorting"
OnRowCommand="gvSupplierCustomerList_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Customer Id" HeaderStyle-HorizontalAlign="Left" SortExpression="CustomerId">
<ItemTemplate>
<asp:Label ID="lblCustomerId" runat="server" Text='<%# ((ITB.DAL.LinqObjects.Customer)Container.DataItem).CustomerId %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First Name" HeaderStyle-HorizontalAlign="Left" SortExpression="FirstName">
<ItemTemplate>
<asp:Label ID="lblFirstName" runat="server" Text='<%# ((ITB.DAL.LinqObjects.Customer)Container.DataItem).FirstName %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name" HeaderStyle-HorizontalAlign="Left" SortExpression="LastName">
<ItemTemplate>
<asp:Label ID="lblLastName" runat="server" Text='<%# ((ITB.DAL.LinqObjects.Customer)Container.DataItem).LastName %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Details" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:HyperLink ID="lnkDetails" Text="Details" NavigateUrl='<%# "~/BackOffice/Customers/CustomerDetails.aspx?CustomerId=" + ((ITB.DAL.LinqObjects.Customer)Container.DataItem).CustomerId %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ask" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:HyperLink ID="lnkAsk" Text="Ask" NavigateUrl='<%# "~/BackOffice/Customers/Ask.aspx?CustomerId=" + ((ITB.DAL.LinqObjects.Customer)Container.DataItem).CustomerId %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:LinqDataSource ID="LqCustomerSource" AutoPage="false" runat="server"
OnSelecting="LqCustomerSource_Selecting" AutoSort="False">
</asp:LinqDataSource>
protected void LqCustomerSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
try
{
CustomerDataManager manager = new CustomerDataManager();
string searchName = "";// txtCustomerName.Text.Trim();
int count = 0;
List<Customer> customerList = manager.GetSelectedCustomers(gvCustomerList.PageIndex * 50, 50, searchName, SortExpression, SortDirectionForCustomers, out count);
//List<CustomerInsuranceInfo> infoList = manager.GetCustomerInsuranceDataFromList(customerList);
lblRows.Text = count.ToString();
e.Arguments.StartRowIndex = 0;
e.Arguments.MaximumRows = 50;
e.Arguments.TotalRowCount = count;
if (customerList == null)
e.Cancel = true;
else
e.Result = customerList;
}
catch (Exception ex)
{
ApplicationLogBO.Log(ex);
// Alert(WebsiteUtil.StandardErrorMessage);
e.Cancel = true;
}
}
答案 0 :(得分:0)
好的,看起来你需要在LqCustomerSource_Selecting
中的代码中设置它gvCustomerList.PageSize = 50