1

我正在尝试在 c# 的数据服务器控件之一中编写自定义分页。我的代表没有开火。以下是代码。

我有以下标记:

<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

以下 C# 代码:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            PageSize = 3;
            using (var db = new MyDBEntities())
            {
                Repeater1.DataSource = db.Enquiries.ToList().Take(3);
                Repeater1.DataBind();
                PrintNumber();
            }
        }
    }

    private void PrintNumber()
    {
        using (var db = new MyDBEntities())
        {
            var total = db.Enquiries.Count();
            var division = total / PageSize;
            var mod = total % PageSize;
            totalPages = mod == 0 ? division : division + 1;


            for (int i = 1; i <= totalPages; i++)
            {
                LinkButton btn = new LinkButton();
                btn.Text = i.ToString();
                btn.ID = "PagerButton" + i.ToString();
                btn.Click += new EventHandler(btn_Click);
                PlaceHolder1.Controls.Add(btn);

            }
        }
    }

    protected void btn_Click(object sender, EventArgs e)
    {
        var btn = (Button)sender;
        var txt = btn.Text;
    }

我有以下渲染标记。

<a id="PagerButton1" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$PagerButton1','')">1</a>
<a id="PagerButton2" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$PagerButton2','')">2</a>
<a id="PagerButton3" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$PagerButton3','')">3</a>

单击链接按钮时,我的代表不会触发。请帮忙..谢谢。

4

0 回答 0