我需要在我的网页上分页。我为此使用 PagedDataSource。但我需要在 .aspx 上枚举页面,所以我LinkButtons
动态添加PlaceHolder
并为所有这些页面编写一个Eventhandler
。它显示和工作正常。在第一次点击时Eventhandler
被触发。在第二个它不火。第三个是。等等......有什么想法吗?
protected void Page_Load(object sender, EventArgs e)
{
bindrepeater();
}
private void bindrepeater()
{
var service = new Service();
var coll = service.GetPeople();
PagedDataSource Pds1 = new PagedDataSource();
Pds1.DataSource = coll;
Pds1.AllowPaging = true;
Pds1.PageSize = 10;
Pds1.CurrentPageIndex = CurrentPage;
Repeater1.DataSource = Pds1;
Repeater1.DataBind();
var count = (coll.Count / 10) + 1;
pages.Controls.Clear();
for (int i = 1; i < count; i++)
{
var lb = new LinkButton() { Text = i.ToString(), CssClass = "hrefia" };
lb.Click += new EventHandler(lb_Click);
pages.Controls.Add(lb);
}
}
protected void lb_Click(object sender, EventArgs e)
{
var lb = (LinkButton)sender;
CurrentPage = int.Parse(lb.Text);
bindrepeater();
}
public int CurrentPage
{
get
{
object s1 = this.ViewState["CurrentPage"];
if (s1 == null)
{
return 0;
}
else
{
return Convert.ToInt32(s1);
}
}
set { this.ViewState["CurrentPage"] = value; }
}