首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

急救啊动态添加按钮解决方法

2012-03-05 
急救啊!动态添加按钮动态添加一个按钮可不知道怎么给那个按钮写Click事件麻烦各位帮帮忙,写个获得填写值的

急救啊!动态添加按钮
动态添加一个按钮   可不知道怎么给那个按钮写Click事件麻烦各位帮帮忙,写个获得填写值的事件
先谢了
public   partial   class   _Default   :   System.Web.UI.Page  
{
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                //第一行
                Label   l1   =   new   Label();
                l1.Text   =   "用户名 ";
                TextBox   t1   =   new   TextBox();
                TableCell   tr1_tc1   =   new   TableCell();
                TableCell   tr1_tc2   =   new   TableCell();
                tr1_tc1.Controls.Add(l1);
                tr1_tc2.Controls.Add(t1);
                TableRow   tr1   =   new   TableRow();
                tr1.Cells.Add(tr1_tc1);
                tr1.Cells.Add(tr1_tc2);


                //第二行
                Label   l2   =   new   Label();
                l2.Text   =   "密码 ";
                TextBox   t2   =   new   TextBox();
                t2.TextMode   =   TextBoxMode.Password;
                TableCell   tr2_tc1   =   new   TableCell();
                TableCell   tr2_tc2   =   new   TableCell();
                tr2_tc1.Controls.Add(l2);
                tr2_tc2.Controls.Add(t2);

                TableRow   tr2   =   new   TableRow();
                tr2.Cells.Add(tr2_tc1);
                tr2.Cells.Add(tr2_tc2);

                Button   b1   =   new   Button();
                b1.Text   =   "登录 ";
                TableCell   tr3_tc1   =   new   TableCell();
                tr3_tc1.Controls.Add(b1);
                TableRow   tr3   =   new   TableRow();
                tr3.Cells.Add(tr3_tc1);
                Table1.Rows.Add(tr1);
                Table1.Rows.Add(tr2);
                Table1.Rows.Add(tr3);

                //怎么添加Click事件   不知道     麻烦各位帮忙     随便给个获得   上面所填写的值的事件咯


        }
       

}

[解决办法]
Button b1 = new Button();
b1.Text = "登录 ";
TableCell tr3_tc1 = new TableCell();

》》》


Button b1 = new Button();
b1.Click += new EventHandler(b1_Click); // 在这里
b1.Text = "登录 ";
TableCell tr3_tc1 = new TableCell();


// 事件处理程序
protected void b1_Click(object sender, EventArgs e)
{
// ...
}
[解决办法]
每个控件 都给一个ID

TextBox t1 = (TextBox)TableID.FindControl( "ID ");

这样就能找到控件了
然后就可以操作了啊

热点排行