当list对象是网格的数据源时,如何实现自定义分页: 我有存储过程来根据分页检索数据。 SP的第一列结果是记录总数(此处为grid.VirtualItemCount = objpurchaserequisitionDetails [0] .intTotalRows)。 注意:在大多数情况下,他们使用TableAdapter。如何在不破坏当前结构的情况下实现Paging
我的网格aspx代码是
<telerik:RadGrid ID="gv_enquiry" runat="server" AllowPaging="true" OnPageIndexChanged="gv_enquiry_PageIndexChanged"
OnPageSizeChanged="gv_enquiry_PageSizeChanged" OnItemCommand="gv_enquiry_ItemCommand">
<PagerStyle Mode="NumericPages" />
<MasterTableView AutoGenerateColumns="false">
<Columns>
<telerik:GridTemplateColumn HeaderText="Reference" ItemStyle-HorizontalAlign="Left"
HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<a class="grdlink" href='<%# String.Concat("PurchaseRequisitionDetailsView.aspx?id=",Eval("intpurchaseenquiryId")) %>'>
<asp:Label ID="lblreff" runat="server" Text='<%# Eval("strReference") %>'></asp:Label>
<asp:HiddenField ID="hdfGRNId" runat="server" Value='<%# Eval("intpurchaseenquiryId") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Department" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lbldeptname" runat="server" Text='<%# Eval("strDepartmentName") %>'></asp:Label>
<%-- <asp:Label ID="lbl_deptid" runat="server" Text='<%# Eval("intDepartmentId") %>'></asp:Label>--%>
<%-- <asp:HiddenField ID="hf_deptid" runat="server" Text='<%# Eval("intDepartmentId") %>' />--%>
<%-- <asp:Label ID="Label1" runat="server" Text=""></asp:Label>--%>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Customer" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblcusname" runat="server" Text='<%# Eval("strCustomername") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Requested Delivery Date" ItemStyle-HorizontalAlign="Center"
HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblpurdt" runat="server" Text='<%# IMSBusinessLayer.SettingManager.ConvertDateToString(Eval("dtpurchaseDate").ToString(),Session["BranchId"].ToString()).ToShortDateString() %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Item Type" ItemStyle-HorizontalAlign="Left"
HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblstatus" runat="server" Text='<%# Eval("strstatus") %>'></asp:Label>
<%--<asp:Label ID="lblitmtype" runat="server" Text='<%# (Eval("intstatus").ToString()=="1") ?"Inventory Item" : "Non-Inventory Item" %>'></asp:Label>--%>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Location" ItemStyle-HorizontalAlign="Left"
HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblloc" runat="server" Text='<%# Eval("strLocationName") %>'></asp:Label>
<%--<asp:Label ID="Label4" runat="server" Text=""></asp:Label>--%>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Place Enquiry" ItemStyle-HorizontalAlign="Left"
HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblclear" runat="server" Text='<%# (Eval("strstatus").ToString()=="Inventory Item") ? String.Concat(String.Concat("<a class=\"grdlink\" href=\"PurchaseEnquiry_NewLayout.aspx?ReqId=",Eval("intpurchaseenquiryId")),"\" >Place Inventory Enquiry</a>") :String.Concat(String.Concat("<a class=\"grdlink\" href=\"PurchaseEnquiry_NonInventoryItemNewLayout.aspx?ReqId=",Eval("intpurchaseenquiryId")),"\" >Place NonInventory Enquiry</a>") %>'></asp:Label>
<%-- <asp:HiddenField ID="hf_statusid" runat="server" value='<%# Eval("intstatus") %>' />--%>
<asp:Label ID="lbl_statusid" Visible="false" runat="server" Text='<%# Eval("strstatus") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="chk_Select" runat="server" AutoPostBack="true" OnCheckedChanged="chk_select_CheckedChanged" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Edit Requisition" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="imgbtnEdit" ImageUrl="~/images/edit.gif" CommandName="EditPurchaseRequisition"
CausesValidation="false" PostBackUrl='<%# (Eval("Iscleared").ToString()=="True") ? "#": String.Concat("purchase_requisition.aspx?RequisitionId=",Eval("intpurchaseenquiryId")) %>'
runat="server" ToolTip="Edit PurchaseRequisition" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Print" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle">
<ItemTemplate>
<asp:ImageButton ID="ImgPrint" ImageUrl="~/images/printer.png" runat="server" ImageAlign="AbsMiddle"
ToolTip="Print Requisition" CommandName="print" CommandArgument='<%# Eval("intpurchaseenquiryId") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<PagerTemplate>
<asp:Panel ID="PagerPanel" Style="padding: 6px; line-height: 24px" runat="server">
<div style="float: left">
<span style="margin-right: 3px;">Page size:</span>
<telerik:RadComboBox ID="RadComboBox1" DataSource="<%# new object[]{10, 50, 100, 250} %>"
Style="margin-right: 20px;" Width="40px" SelectedValue='<%# DataBinder.Eval(Container, "Paging.PageSize") %>'
runat="server" OnClientSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
</telerik:RadComboBox>
</div>
<div style="margin: 0px; float: right;">
Displaying page
<%# (int)DataBinder.Eval(Container, "Paging.CurrentPageIndex") + 1 %>
of
<%# DataBinder.Eval(Container, "Paging.PageCount")%>
, items
<%# (int)DataBinder.Eval(Container, "Paging.FirstIndexInPage") + 1 %>
to
<%# (int)DataBinder.Eval(Container, "Paging.LastIndexInPage") + 1 %>
of
<%# DataBinder.Eval(Container, "Paging.DataSourceCount")%>
</div>
<div style="width: 260px; margin: 0px; padding: 0px; float: left; margin-right: 10px;
white-space: nowrap;">
<asp:Button ID="Button1" EnableTheming="false" runat="server" OnClientClick="changePage('first'); return false;"
CommandName="Page" CommandArgument="First" Text=" " CssClass="PagerButton FirstPage" />
<asp:Button ID="Button2" runat="server" EnableTheming="false" OnClientClick="changePage('prev'); return false;"
CommandName="Page" CommandArgument="Prev" Text=" " CssClass="PagerButton PrevPage" />
<span style="vertical-align: middle;">Page:</span>
<telerik:RadNumericTextBox ID="RadNumericTextBox1" Width="25px" Value='<%# (int)DataBinder.Eval(Container, "Paging.CurrentPageIndex") + 1 %>'
runat="server">
<ClientEvents OnValueChanged="RadNumericTextBox1_ValueChanged" />
<NumberFormat DecimalDigits="0" />
</telerik:RadNumericTextBox>
<span style="vertical-align: middle;">of
<%# DataBinder.Eval(Container, "Paging.PageCount")%>
</span>
<asp:Button ID="Button3" runat="server" EnableTheming="false" OnClientClick="changePage('next'); return false;"
CommandName="Page" CommandArgument="Next" Text=" " CssClass="PagerButton NextPage" />
<asp:Button ID="Button4" runat="server" EnableTheming="false" OnClientClick="changePage('last'); return false;"
CommandName="Page" CommandArgument="Last" Text=" " CssClass="PagerButton LastPage" />
</div>
<asp:Panel runat="server" ID="NumericPagerPlaceHolder" />
</asp:Panel>
</PagerTemplate>
</MasterTableView>
</telerik:RadGrid>
此网格的javascript是
<script type="text/javascript">
var tableView = null;
function pageLoad(sender, args) {
tableView = $find("<%= gv_enquiry.ClientID %>").get_masterTableView();
}
function RadComboBox1_SelectedIndexChanged(sender, args) {
tableView.set_pageSize(sender.get_value());
}
function changePage(argument) {
tableView.page(argument);
}
function RadNumericTextBox1_ValueChanged(sender, args) {
tableView.page(sender.get_value());
}
</script>
现在用于执行网格绑定的cs页面:
List<MdlPurchaseinvoice> objpurchaserequisitionDetails = new List<MdlPurchaseinvoice>();
objpurchaserequisitionDetails = PurchaseManager.GetPurchaseRequisitionMasterForGrid(item_type, dep_id, rec_to, dtfromdate, dttodate, guidCompanyBranchId,ref_no);
gv_enquiry.DataSource = objpurchaserequisitionDetails;
gv_enquiry.DataBind();
//PurchaseManager.cs
public List<MdlPurchaseinvoice> GetPurchaseRequisitionMasterForGrid(int item_type, int dep_id, int rec_to, DateTime fromdt, DateTime todate, Guid guidcompanybranchId, string ref_no, int startitem, int enditem)
{
IDataReader datareader = null;
List<MdlPurchaseinvoice> objpurchaseRequisitions = new List<MdlPurchaseinvoice>();
try
{
SqlParameter[] objsqlparameter = new SqlParameter[9];
objsqlparameter[0] = new SqlParameter("@item_type", SqlDbType.Int);
objsqlparameter[0].Value = item_type;
objsqlparameter[1] = new SqlParameter("@dep_id", SqlDbType.Int);
objsqlparameter[1].Value = dep_id;
objsqlparameter[2] = new SqlParameter("@rec_to", SqlDbType.Int);
objsqlparameter[2].Value = rec_to;
objsqlparameter[3] = new SqlParameter("@fromdt", SqlDbType.Date);
objsqlparameter[3].Value = fromdt;
objsqlparameter[4] = new SqlParameter("@todate", SqlDbType.Date);
objsqlparameter[4].Value = todate;
objsqlparameter[5] = new SqlParameter("@guidcompanybranchId", SqlDbType.UniqueIdentifier);
objsqlparameter[5].Value = guidcompanybranchId;
objsqlparameter[6] = new SqlParameter("@ref_no", SqlDbType.VarChar);
objsqlparameter[6].Value = ref_no;
objsqlparameter[7] = new SqlParameter("@startitem", SqlDbType.Int);
objsqlparameter[7].Value = startitem;
objsqlparameter[8] = new SqlParameter("@enditem", SqlDbType.Int);
objsqlparameter[8].Value = enditem;
if (base.Transaction != null)
{
datareader = _helper.ExecuteReader(base.Transaction, "usp_getPurchaserequisitionMasterForGrid", objsqlparameter);
}
else
{
datareader = _helper.ExecuteReader(base.ConnectionString, "usp_getPurchaserequisitionMasterForGrid", objsqlparameter);
}
while (datareader.Read())
{
MdlPurchaseinvoice objpurchaseRequisition = new MdlPurchaseinvoice();
if (!datareader.IsDBNull(datareader.GetOrdinal("TotatRows")))
objpurchaseRequisition.intTotalRows = datareader.GetInt32(datareader.GetOrdinal("TotatRows"));
if (!datareader.IsDBNull(datareader.GetOrdinal("purchase_requisition_id")))
objpurchaseRequisition.intpurchaseenquiryId = datareader.GetInt32(datareader.GetOrdinal("purchase_requisition_id"));
if (!datareader.IsDBNull(datareader.GetOrdinal("purchase_requisition_date")))
objpurchaseRequisition.dtpurchaseDate = datareader.GetDateTime(datareader.GetOrdinal("purchase_requisition_date"));
if (!datareader.IsDBNull(datareader.GetOrdinal("reference")))
objpurchaseRequisition.strReference = datareader.GetString(datareader.GetOrdinal("reference"));
if (!datareader.IsDBNull(datareader.GetOrdinal("company_branch_id")))
objpurchaseRequisition.guidCompanyBranchId = datareader.GetGuid(datareader.GetOrdinal("company_branch_id"));
if (!datareader.IsDBNull(datareader.GetOrdinal("user_id")))
objpurchaseRequisition.guidUserId = datareader.GetGuid(datareader.GetOrdinal("user_id"));
if (!datareader.IsDBNull(datareader.GetOrdinal("remark")))
objpurchaseRequisition.strRemark = datareader.GetString(datareader.GetOrdinal("remark"));
if (!datareader.IsDBNull(datareader.GetOrdinal("receiveto")))
objpurchaseRequisition.intLocationId = datareader.GetInt32(datareader.GetOrdinal("receiveto"));
if (!datareader.IsDBNull(datareader.GetOrdinal("requisition_type")))
objpurchaseRequisition.intstatus = datareader.GetInt32(datareader.GetOrdinal("requisition_type"));
if (objpurchaseRequisition.intstatus == 1)
{
objpurchaseRequisition.strstatus = "Inventory Item";
}
else
{
objpurchaseRequisition.strstatus = "Non-Inventory Item";
}
if (!datareader.IsDBNull(datareader.GetOrdinal("department_id")))
objpurchaseRequisition.intDepartmentId = datareader.GetInt32(datareader.GetOrdinal("department_id"));
if (!datareader.IsDBNull(datareader.GetOrdinal("location_name")))
objpurchaseRequisition.strLocationName = datareader.GetString(datareader.GetOrdinal("location_name"));
if (!datareader.IsDBNull(datareader.GetOrdinal("department_name")))
objpurchaseRequisition.strDepartmentName = datareader.GetString(datareader.GetOrdinal("department_name"));
if (!datareader.IsDBNull(datareader.GetOrdinal("customer_branch_id")))
objpurchaseRequisition.intCustomerBranchId = datareader.GetInt32(datareader.GetOrdinal("customer_branch_id"));
if (!datareader.IsDBNull(datareader.GetOrdinal("customer_branch_name")))
objpurchaseRequisition.strCustomerBranchname = datareader.GetString(datareader.GetOrdinal("customer_branch_name"));
if (!datareader.IsDBNull(datareader.GetOrdinal("customer_name")))
objpurchaseRequisition.strCustomername = datareader.GetString(datareader.GetOrdinal("customer_name"));
if (!datareader.IsDBNull(datareader.GetOrdinal("delivery_instructions")))
objpurchaseRequisition.strDeliveryInstructions = datareader.GetString(datareader.GetOrdinal("delivery_instructions"));
if (!datareader.IsDBNull(datareader.GetOrdinal("doc_required")))
objpurchaseRequisition.strDocRequired = datareader.GetString(datareader.GetOrdinal("doc_required"));
if (!datareader.IsDBNull(datareader.GetOrdinal("customer_id")))
objpurchaseRequisition.intCustomerId = datareader.GetInt32(datareader.GetOrdinal("customer_id"));
if (!datareader.IsDBNull(datareader.GetOrdinal("department_id")))
objpurchaseRequisition.intDepartmentId = datareader.GetInt32(datareader.GetOrdinal("department_id"));
objpurchaseRequisitions.Add(objpurchaseRequisition);
}
}
catch (Exception)
{}
finally
{
if (datareader != null)
datareader.Close();
}
return objpurchaseRequisitions;
}
,存储过程是
ALTER PROCEDURE [dbo].[usp_getPurchaserequisitionMasterForGrid]
@item_type int,
@dep_id int,
@rec_to int,
@fromdt date,
@todate date,
@guidcompanybranchId UniqueIdentifier,
@ref_no varchar(50),
@startitem int,
@enditem int
AS
DECLARE @tbl TABLE(
RowNo int
, purchase_Requisition_id int
, purchase_Requisition_date date
, reference varchar(50)
, company_branch_id uniqueidentifier
, user_id uniqueidentifier
, remark text
, receiveto int
, requisition_type int
, department_id int
, location_name varchar(50)
, department_name varchar(50)
, customer_branch_id int
, customer_branch_name varchar(50)
, customer_name varchar(50)
, delivery_instructions varchar(max)
, doc_required varchar(max)
, customer_id int)
Insert into @tbl
SELECT * FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY purchase_Requisition_id DESC) AS RowNo,
purchase_Requisition_id,
purchase_Requisition_date,
reference,
tbl_purchase_RequisitionMaster.company_branch_id,
user_id,
remark,
receiveto,
requisition_type,
tbl_purchase_RequisitionMaster.department_id,
tbl_inventory_location_master.location_name,
tbl_department_name.department_name,
tbl_purchase_RequisitionMaster.customer_branch_id,
tbl_customer_branch_master.name AS customer_branch_name,
tbl_customer_master.name AS customer_name,
delivery_instructions,
doc_required,
tbl_customer_master.customer_id
FROM tbl_purchase_RequisitionMaster
LEFT OUTER JOIN tbl_inventory_location_master
ON tbl_inventory_location_master.location_id = tbl_purchase_RequisitionMaster.receiveto
INNER JOIN tbl_department_name
ON tbl_department_name.department_id = tbl_purchase_RequisitionMaster.department_id
LEFT OUTER JOIN tbl_customer_branch_master
INNER JOIN tbl_customer_master
ON tbl_customer_master.customer_id = tbl_customer_branch_master.customer_id
ON tbl_customer_branch_master.customer_branch_id = tbl_purchase_RequisitionMaster.customer_branch_id
WHERE (tbl_purchase_RequisitionMaster.company_branch_id = @guidcompanybranchId)
AND (tbl_purchase_RequisitionMaster.department_id = (CASE WHEN @dep_id = 0 THEN tbl_purchase_RequisitionMaster.department_id ELSE @dep_id END))
AND (tbl_purchase_RequisitionMaster.receiveto = (CASE WHEN @rec_to = 0 THEN tbl_purchase_RequisitionMaster.receiveto ELSE @rec_to END))
AND (tbl_purchase_RequisitionMaster.purchase_requisition_date > = @fromdt)
AND (tbl_purchase_RequisitionMaster.purchase_requisition_date <= @todate)
AND (tbl_purchase_RequisitionMaster.requisition_type = (CASE WHEN @item_type=0 THEN tbl_purchase_RequisitionMaster.requisition_type ELSE (CASE WHEN @item_type = 1 THEN 1 ELSE 2 END) END))
AND (tbl_purchase_RequisitionMaster.reference = (CASE WHEN @ref_no='' OR @ref_no = null THEN tbl_purchase_RequisitionMaster.reference ELSE @ref_no END))
) AS REQMASTER
DECLARE @TOTROWS int = (SELECT COUNT(*) FROM @tbl)
SELECT @TOTROWS AS TotatRows
, RowNo AS RowNo
, purchase_Requisition_id
, purchase_Requisition_date
, reference
, company_branch_id
, user_id
, remark
, receiveto
, requisition_type
, department_id
, location_name
, department_name
, customer_branch_id
, customer_branch_name
, customer_name
, delivery_instructions
, doc_required
, customer_id
FROM @tbl
WHERE RowNo > @startitem AND RowNo <= @enditem
ORDER BY purchase_Requisition_id DESC
RETURN