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

得取数据的有关问题?

2012-01-05 
得取数据的问题???????LinkButtonlkbnewLinkButton()lkb.Text test lkb.Click+newEventHandler(Lin

得取数据的问题???????
LinkButton   lkb   =   new   LinkButton();
lkb.Text= "test ";
lkb.Click   +=   new   EventHandler(LinkButton_Click);

LinkButton   lkb2   =   new   LinkButton();
lkb2.Text   =   "test2 ";
lkb2.Click   +=   new   EventHandler(LinkButton_Click);

protected   void   LinkButton_Click(object   sender,   EventArgs   e)
{
        Response.Write( "按到了 ");
}

现在我想知道怎么分别是由那个LinkButton传来的,应该怎么来区别,例如字符或数据之类的取得???不会做,请教大家!!谢谢!!!!


[解决办法]
你要先指定它的ID

LinkButton lkb = new LinkButton();
lkb.ID = "mytest1 ";
lkb.Text = "test ";
lkb.Click += new EventHandler(LinkButtonx_Click);
this.form1.Controls.Add(lkb);

LinkButton lkb2 = new LinkButton();
lkb2.ID = "mytest2 ";
lkb2.Text = "test2 ";
lkb2.Click += new EventHandler(LinkButtonx_Click);
this.form1.Controls.Add(lkb2);


然后这样得到

protected void LinkButton_Click(object sender, EventArgs e)
{
Response.Write( "按到了 "+((LinkButton)sender).ID);
}

热点排行