为了账号安全,请及时绑定邮箱和手机立即绑定

循环动态添加的事件点击2次只执行一次

循环动态添加的事件点击2次只执行一次

千巷猫影 2018-12-07 09:20:11
protected void Page_Load(object sender, EventArgs e)    {        if (!Page.IsPostBack)        {            ViewState["textname"] = "";            ViewState["sum"] = 0;        }        if (Convert.ToInt32(ViewState["sum"].ToString()) > 1)        {            SeachData(Convert.ToInt32(ViewState["sum"].ToString()));        }    }       private void SeachData(int sum)    {        this.PlaceHolder1.Controls.Clear();        double index = sum / 10;        if (index > 10)        {            for (int i = 1; i <= 10; i++)            {                LinkButton lb = new LinkButton();                lb.Text = String.Format("{0}", i);                lb.Click += new EventHandler(lb_Click);                this.PlaceHolder1.Controls.Add(lb);            }        }        else        {            for (int i =1; i <= index; i++)            {                LinkButton lb = new LinkButton();                lb.Text = String.Format("{0}",i);                lb.Click+=new EventHandler(lb_Click);                this.PlaceHolder1.Controls.Add(lb);            }        }    }          #region 点击事件    void lb_Click(object sender, EventArgs e)    {        LinkButton lb = (LinkButton)sender;        string str = lb.Text;        int index = Convert.ToInt32(lb.Text);//获取当前点击的页数     }    #endregion
查看完整描述

1 回答

?
婷婷同学_

TA贡献1844条经验 获得超8个赞

if (Convert.ToInt32(ViewState["sum"].ToString()) > 1) { SeachData(Convert.ToInt32(ViewState["sum"].ToString())); } 这里事件被重新绑定了
查看完整回答
反对 回复 2019-01-21
  • 1 回答
  • 0 关注
  • 639 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信