您的位置:首页 > 其它

【小技巧】在GridView控件外获取GridView内的控件

2007-07-07 17:19 323 查看
想获取GridView控件内的子控件可以利用GridView自身的事件来处理。
比如说:

利用RowDataBound事件:

protected void RowDataBoumd(object sender, GridViewRowEventArgs e)
{
TextBox t = e.Row.FindControl("TextBox") as TextBox;
Response.Write(t.Text);
}

更多方式请点击这里

如果想要通过GridView控件外的某个控件,比如说<asp:Button ... />,则可以通过循环GridView控件的GridViewRow来获得,当然你是可以指定获取某行的,假如你能提供行号。
那这个Button的事件应该包含类似下面的代码:

foreach (GridViewRow row in GridView1.Rows)
{

this.Lable1.Text += "<br />" + (row.FindControl("txt_input") as TextBox).Text;

}

哈,希望我的标题不会是哗众取宠。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: