LinkButton的内部中继分页ASP.Net [英] Linkbutton inside Repeater for paging ASP.Net
问题描述
我在做与带来了很多来自MSSQL信息的搜索网页。我所做的是在网站上可以看到,只返回页面中的存储过程。
I'm doing a webpage with a search that brings a lot of information from MSSQL. What I did is a stored procedure that return only the page to be seen on the website.
现在我的传呼工作,因为我需要表现出比谷歌类似的东西。如果你是第1页,他们表现出前10页,如果你是在第19页,他们自9页显示至28。
Right now I'm working on the paging as I need to show something similar than google. If you are at page 1 they show first 10 pages and if you are at page 19 they show since page 9 to 28.
我想显示页码的最佳选择是使用一个中继器内的一个LinkButton。我现在的问题是,我不知道拿在投递的页面数的最佳方式。
I think the best option to show the page numbers is using a linkbutton inside a repeater. The problem that I have now is that I do not know the best way to take the page number at postback.
做一个快速的样品给我分配一个ArrayList repeater.datasource:
Doing a quick sample I assigned an ArrayList to repeater.datasource:
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument="<%# Container.DataItem %>"><%# Container.DataItem %></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
<asp:LinkButton ID="LinkButton2" runat="server" CommandArgument="4654">Test #1</asp:LinkButton>
在我Default.aspx.cs文件,我的下一个code
At my Default.aspx.cs file I have the next code
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
string x = LinkButton2.CommandArgument;
//string y = LinkButton1.CommandArgument;
//I know this line will not work since the Linkbutton1 is inside the Repeater.
}
我该怎么做才能让它的工作原理?
What Shall I do to make it works?
有没有人有这个分页更好的解决办法?
Does anyone has a better solution for this paging?
感谢您
杰里
推荐答案
您正在寻找的ItemCommand事件:
You're looking for the ItemCommand event:
<asp:Repeater ID="Repeater1" OnItemCommand="ItemCommand" runat="server">
<ItemTemplate>
<asp:LinkButton CommandName="ButtonEvent" CommandArgument="<%# Container.DataItem %>" Text="<%#Container.DataItem %>" runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
背后code:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Repeater1.DataSource = Enumerable.Range(1, 10);
Repeater1.DataBind();
}
}
protected void ItemCommand(Object Sender, RepeaterCommandEventArgs e)
{
Response.Write("The no. " + ((LinkButton)e.CommandSource).Text + " button was clicked!");
}
...但你真的确定你需要的LinkButton?一个普通的HTML锚标记可能会工作得细,它的绒毛少。 :)
... but are you really sure you need the LinkButton? A plain HTML anchor tag might work just as fine, and it's less fuzz. :)
这篇关于LinkButton的内部中继分页ASP.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!