在Asp.Net中进行自定义分页 [英] Custom Paging in Asp.Net
问题描述
我正在我的项目中进行自定义分页。但记录数大约是1500.我每页显示10条记录。总共有150页。所以我显示如下。
I am doing custom paging in my project. But the record count is around 1500. And i am displaying 10 records per page. So there are total of 150 pages. So I am displaying as below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25...150
- > ......并禁用150
这个我已经完成了,我只能查看util 25页:(现在我想处理下面的情况
问题==>我想点击...以便显示如下
--> ... and 150 is disabled
this I have done and I am able to view up util 25 pages only :( now I want to handle the situation as below
Question ==> I want to click on ... so that it displays as below
1...26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50...150
当我点击50后,它应显示为
And when I click on ... after 50 it should display as
1...51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75...150
请帮助我
------------------- -------------代码(的.cs)-------------------------------- ------------------
Kindly Help me
--------------------------------code(.cs)--------------------------------------------------
protected void ddlhub_SelectedIndexChanged(object sender, EventArgs e)
{
intRoleId = Convert.ToInt32(Session[TMS.Common.CommonConstants.CONST_ROLE_ID]);
BindGrid(0, GridZeroApprovedKm.PageSize);
gridcolumninvisible();
}
protected void BindGrid(int pageindex, int pagesize)
{
string Modified_by = Session[TMS.Common.CommonConstants.CONST_USER_ID].ToString();
TMSDatabase TMSDb = TMSDatabase.CreateInstance();
string ConnectionString = TMSDb.ConnectionString.ToString();
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("APPROVED_KM", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@HUB_ID", SqlDbType.Int));
cmd.Parameters.Add(new SqlParameter("@Pageindex", SqlDbType.Int));
cmd.Parameters.Add(new SqlParameter("@pageSize", SqlDbType.Int));
cmd.Parameters.Add(new SqlParameter("@totalrows", SqlDbType.Int));
cmd.Parameters.Add(new SqlParameter("@Modified_by", SqlDbType.VarChar));
cmd.Parameters["@totalrows"].Direction = ParameterDirection.Output;
cmd.Parameters["@HUB_ID"].Value = ddlhub.SelectedValue;
cmd.Parameters["@Pageindex"].Value = pageindex;
cmd.Parameters["@pageSize"].Value = pagesize;
cmd.Parameters["@Modified_by"].Value = Modified_by;
IDataReader idr = cmd.ExecuteReader();
GridZeroApprovedKm.DataSource = idr;
GridZeroApprovedKm.DataBind();
if (GridZeroApprovedKm.Rows.Count == 0)
{
msgLabel.Text = "No records found for the selected search criteria.";
msgLabel.Visible = true;
return;
}
else
{
msgLabel.Text = "";
}
MsgUpdatePanel.Update();
gridcolumninvisible();
idr.Close();
con.Close();
int recordcount = Convert.ToInt32(cmd.Parameters["@totalrows"].Value);
if (pageindex == 0)
{
this.RepeaterBind(0, GridZeroApprovedKm.PageSize, recordcount);
}
else
{
this.RepeaterBind(pageindex, GridZeroApprovedKm.PageSize, recordcount);
}
}
protected void RepeaterBind(int pageindex, int pagesize, int totalrows)
{
int totalpages = totalrows / pagesize;
if ((totalrows % pagesize) != 0)
{
totalpages += 1;
}
List<ListItem> pages = new List<ListItem>();
if (totalpages > 1)
{
for (int i = 1; i <= totalpages; i++)
{
if (i <= 25)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));
}
else
{
pages.Add(new ListItem("...", "...", false));
pages.Add(new ListItem(totalpages.ToString(), totalpages.ToString(), false));
break;
}
}
}
RepeaterForPaging.DataSource = pages;
RepeaterForPaging.DataBind();
}
protected void Page_Changed_click(object sender, EventArgs e)
{
//int totalrows = 0;
int pageindex = int.Parse((sender as LinkButton).CommandArgument);
pageindex = pageindex - 1;
GridZeroApprovedKm.PageIndex = pageindex;
BindGrid(pageindex, GridZeroApprovedKm.PageSize);
}
////我在RepeaterBind函数中处理显示25 pages ....
//// i am handling in RepeaterBind function the display of 25 pages....
推荐答案
您需要对基于代码的点击页面进行更改。查看此文章
ASP.NET的寻呼机控件 [ ^ ] < br $> b $ b
jQuery分页插件 [ ^ ]
You need to do changes in your code based clicked page no. Check this article
Pager Control for ASP.NET[^]
jQuery pagination plugins[^]
我已经用这种方式解决了它。虽然它看起来有点笨拙但有些如何解决问题。
I have solved it in this way. Though it looks bit clumsy but some how it solved the problem.
protected void RepeaterBind(int pageindex, int pagesize, int totalrows)
{
int j=1;
int k = 1;
int l;
int mod;
mod = (pageindex / 25);
int totalpages = totalrows / pagesize;
if ((totalrows % pagesize) != 0)
{
totalpages += 1;
}
List<ListItem> pages = new List<ListItem>();
if (totalpages > 1)
{
if (pageindex == 0)
{
for (int i = k; i <= 26; i++)
{
if (i <= 25)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));
}
else
{
pages.Add(new ListItem("...", (i).ToString(), true));
pages.Add(new ListItem(totalpages.ToString(), totalpages.ToString(), true));
break;
}
}
}
if (mod != 0 && pageindex!=0)
{
pages.Add(new ListItem(j.ToString(), j.ToString(), true));
pages.Add(new ListItem("...", (mod*25).ToString(), true));
l = (totalpages / 25)-(pageindex / 25);
if (l >= 2 )
{
for (int i = ((25 * (mod)) + 1); i <= (((25 * (mod)) + 1) + 25); i++)
{
if (i <= (((25 * (mod)) + 1) + 24))
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));
}
else
{
pages.Add(new ListItem("...", (i).ToString(), true));
pages.Add(new ListItem(totalpages.ToString(), totalpages.ToString(), true));
break;
}
}
}
else
{
if (l == 1 && ((pageindex % 5) == 4))
{
for (int i = ((25 * (mod)) + 1); i <= (((25 * (mod)) + 1) + 25); i++)
{
if (i <= (((25 * (mod)) + 1) + 24))
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));
}
else
{
pages.Add(new ListItem("...", (i).ToString(), true));
pages.Add(new ListItem(totalpages.ToString(), totalpages.ToString(), true));
break;
}
}
}
else
{
for (int i = ((25 * (mod)) + 1); i <= totalpages; i++)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));
}
}
}
}
else if (mod == 0 && pageindex != 0)
{
for (int i = k; i <= 26; i++)
{
if (i <= 25)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != (pageindex + 1)));
}
else
{
pages.Add(new ListItem("...", (i).ToString(), true));
pages.Add(new ListItem(totalpages.ToString(), totalpages.ToString(), true));
break;
}
}
}
}
RepeaterForPaging.DataSource = pages;
RepeaterForPaging.DataBind();
}
这篇关于在Asp.Net中进行自定义分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!