寻呼代码问题
本文关键字:问题 代码 | 更新日期: 2023-09-27 18:00:50
我在下面写了几行代码,用于在asp.net中使用中继器控制作为实现分页
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" OnClick="pagenexte_Click"
data-rel="tooltip" data-original-title="previous page.">«</asp:LinkButton>
<asp:Repeater ID="rptPager" OnItemDataBound="rptPager_ItemDataBound" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>' Enabled='<%# Eval("Enabled") %>' OnClick="Page_Changed"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="false" OnClick="pagenext_Click"
data-rel="tooltip" data-original-title="next page.">»
</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="false" OnClick="imgnext_Click"
data-rel="tooltip" data-original-title="next page." Visible="false"> »
</asp:LinkButton>
在cs文件中作为
public void UpdatePageLables(int aPageCount)
{
if (!Page.IsPostBack)
{
Session["pages"] = null;
}
PageCount = (int)Math.Ceiling((decimal)aPageCount / PageSize);
int recordCount = PageCount;
if (PageSizeChanged != null)
{
HiddenField hd = new HiddenField();
int current;
current = PageIndex;
int pre;
int Next;
double dblPageCount = (double)((decimal)recordCount / decimal.Parse(lstPageSize.SelectedValue));
int pageCount = PageCount;
List<ListItem> pages = new List<ListItem>();
if (pageCount > 0)
{
// pages.Add(new ListItem("First", "1", PageIndex > 1));
current = PageIndex;
pre = --PageIndex;
PageIndex = current;
// pages.Add(new ListItem("Previous", pre.ToString(), PageIndex > 1));
for (int i = 1; i <= aPageCount; i++)
{
if (i <= 5)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != PageIndex));
}
}
int currentPage = PageIndex;
Next = ++PageIndex;
PageIndex = currentPage;
//pages.Add(new ListItem("Next", Next.ToString(), PageIndex < pageCount));
// pages.Add(new ListItem("Last", pageCount.ToString(), PageIndex < pageCount));
hd.Value = (pre.ToString());
}
if (Session["pages"] != null)
{
rptPager.DataSource = Session["pages"];
rptPager.DataBind();
}
else
{
rptPager.DataSource = pages;
rptPager.DataBind();
}
Session["lastnumber"] = 5;
Session["pagecount"] = aPageCount;
Session["orignalpages"] = pages;
}
}
protected void pagenext_Click(object sender, EventArgs e)
{
List<ListItem> pages = new List<ListItem>();
int pagecount = Convert.ToInt32(Session["pagecount"].ToString());
int lastnumber = Convert.ToInt32(Session["lastnumber"].ToString());
if (lastnumber > pagecount)
{
Session["lastnumber"] = 1;
lastnumber = 1;
Session["pagecount"] = pagecount;
Session["orignalpages"] = pages;
}
int limit = lastnumber + 5;
for (int i = lastnumber; i <= pagecount; i++)
{
if (i <= limit)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != PageIndex));
}
else
{
rptPager.DataSource = Session["orignalpages"];
rptPager.DataBind();
}
}
Session["lastnumber"] = limit;
Session["pagecount"] = pagecount;
Session["pages"] = pages;
rptPager.DataSource = pages;
rptPager.DataBind();
}
protected void pagenexte_Click(object sender, EventArgs e)
{
List<ListItem> pages = new List<ListItem>();
int pagecount = Convert.ToInt32(Session["pagecount"].ToString());
int lastnumber = Convert.ToInt32(Session["lastnumber"].ToString());
if (lastnumber > pagecount)
{
Session["lastnumber"] = pagecount - 5;
lastnumber = pagecount - 5;
Session["pagecount"] = pagecount;
Session["orignalpages"] = pages;
}
else
{
Session["lastnumber"] = 1;
lastnumber = 1;
Session["pagecount"] = pagecount;
Session["orignalpages"] = pages;
}
int limit = lastnumber + 5;
for (int i = lastnumber; i <= pagecount; i++)
{
if (i <= limit && i>0)
{
pages.Add(new ListItem(i.ToString(), i.ToString(), i != PageIndex));
}
else
{
//rptPager.DataSource = Session["orignalpages"];
//rptPager.DataBind();
}
}
Session["lastnumber"] = limit;
Session["pagecount"] = pagecount;
Session["pages"] = pages;
rptPager.DataSource = pages;
rptPager.DataBind();
}
它工作正常,但不按要求显示页码。基本上,我希望它应该显示为"1 2 3 4 5",然后单击下一个按钮,它应该显示"6 7 8 9 10",然后再次单击下一按钮"11 12 13 14 15"。。。。依此类推。下面的代码生成页码为"1 2 3 4 5"单击下一个按钮"5 6 7 8 9 10",然后单击10 11 12 13 14 15等等…请帮帮我!!!还帮助我改进上一个按钮的代码而且
您可以使用"DataTable"javascript功能来解决此问题。请参阅https://www.datatables.net/.
在这里,你只需要在下面的代码中给出你的表Id。
$(document).ready(function(){
$('#myTable').DataTable();
});