我需要在我的網頁上進行分頁。我爲它使用PagedDataSource。但我需要在.aspx上枚舉頁面,所以我將LinkButtons
動態添加到PlaceHolder
,併爲它們全部寫入Eventhandler
。它顯示和工作正常。在第一次點擊Eventhandler
被解僱。在第二它不開火。在三分之一。等等......任何想法?動態添加LinkButtons不會觸發OnClick事件
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; }
}
你好,問題是,你必須設置一個ID爲您的LinkButton做工精細 – 2012-07-30 07:22:17
我加入它,現在它永遠不會觸發。停下來開火 – levi 2012-07-30 07:25:55
你好,我已經嘗試過了,在設置點擊處理程序之前它起作用了(你確定設置lb.ID = ...)嗎? – 2012-07-30 07:36:26