使用中继器进行寻呼 [英] Paging using repeater
本文介绍了使用中继器进行寻呼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨....
我正在通过repeatr进行分页。我的上一个和下一个按钮正常工作。
但是数字不像1,2一样工作3
我的编码低于
Hi....
I am doing paging through repeatr.My previous and Next button is working.
But Number is not working like as 1,2,3
My coding is below
<div>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<th>Product Id</th>
<th>Product Name</th>
<th>Quantity</th>
<th>Unit Price</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#DataBinder.Eval(Container.DataItem,"pid")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem,"pname") %>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem,"qty") %>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem,"unitprice") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<input type="hidden" id="PageSize" value="5" runat="server"/>
<input type="hidden" id="CurrentPage" value="1" runat="server"/>
<input type="hidden" id="TotalSize" runat="server"/>
<asp:LinkButton ID="Prev" runat="server" Text="<< Previous" OnClick="page_Repeater"><< Previous</asp:LinkButton>
<asp:LinkButton ID="one" runat="server">1</asp:LinkButton>
<asp:LinkButton ID="two" runat="server">2</asp:LinkButton>
<asp:LinkButton ID="Next" runat="server" Text="Next >>" OnClick="page_Repeater">Next >></asp:LinkButton>
</div>
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection("Data Source=.;Initial Catalog=rept;Integrated Security=True");
BuildGrid();
}
public void BuildGrid()
{
da = new SqlDataAdapter("select * from product", con);
ds = new DataSet();
int startRecord = (int.Parse(CurrentPage.Value) - 1) * int.Parse(PageSize.Value);
da.Fill(ds, startRecord, int.Parse(PageSize.Value), "Product");
Repeater1.DataSource = ds.Tables["product"].DefaultView;
Repeater1.DataBind();
cmd = new SqlCommand("select count(*) from product", con);
con.Open();
TotalSize.Value = cmd.ExecuteScalar().ToString();
con.Close();
BuildPagers();
}
public void page_Repeater(object sender, EventArgs e)
{
if (((LinkButton)sender).ID == "Prev")
{
if ((int.Parse(CurrentPage.Value) - 1) >= 0)
{
CurrentPage.Value = (int.Parse(CurrentPage.Value) - 1).ToString();
}
}
else if (((LinkButton)sender).ID == "two")
{
da = new SqlDataAdapter("select * from product", con);
ds = new DataSet();
int startRecord= (int.Parse(CurrentPage.Value)+1);
int a = (int.Parse(PageSize.Value) + 5);
da.Fill(ds, startRecord, a, "Product");
Repeater1.DataSource = ds.Tables["product"].DefaultView;
Repeater1.DataBind();
cmd = new SqlCommand("select count(*) from product", con);
con.Open();
TotalSize.Value = cmd.ExecuteScalar().ToString();
con.Close();
BuildPagers();
}
else if (((LinkButton)sender).ID == "Next")
{
if ((int.Parse(CurrentPage.Value) * int.Parse(PageSize.Value)) < int.Parse(TotalSize.Value))
{
CurrentPage.Value = (int.Parse(CurrentPage.Value) + 1).ToString();
}
}
BuildGrid();
}
public void BuildPagers()
{
if ((int.Parse(CurrentPage.Value) - 1) <= 0)
{
Prev.Enabled = false;
}
else
{
Prev.Enabled = true;
}
if ((int.Parse(CurrentPage.Value) * int.Parse(PageSize.Value)) >= int.Parse(TotalSize.Value))
{
Next.Enabled = false;
}
else
{
Next.Enabled = true;
}
}
推荐答案
看看这篇CP文章,你一定会得到一些帮助:
具有分页和排序功能的中继器 [ ^ ]
这里有一个非常类似于你的要求:
使用ASP.NET转发器控件进行自定义分页 [ ^ ]
Have a look on this CP article, you will surely get some help out:
Repeater with Paging and Sorting Features[^]
Here''s one which is quite similar to your requirement:
Custom Paging with the ASP.NET Repeater Control[^]
这篇关于使用中继器进行寻呼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文