当前位置: 代码迷 >> ASP.NET >> 访问Gridview里的html控件input的有关问题
  详细解决方案

访问Gridview里的html控件input的有关问题

热度:6783   发布时间:2013-02-25 00:00:00.0
访问Gridview里的html控件input的问题
Gridview1里面TemplateField里定义了个input控件,id= "input1 "
在程序里怎样才能访问这个控件呀?
比如我现在要得到它的Text值,
用FindControl好像不能找html控件,
应该怎么做才能实现呢?
谢谢!

------解决方案--------------------------------------------------------
1。
给 input 加上 runat = server

2。
// GridView 的 RowBound 事件中
protected void GridView1_RowBound(object sender, GridViewRowEventArgs e)
{
HtmlInputText npt = e.Row.FindControl( "input1 ") as HtmlInputText;
if(npt != null) Response.Write(npt.Value);
}

// 任意外部按钮
protected void Button1_Click(object sender, EventArgs e)
{
foreach(GridViewRow row in GridView1.Rows) {
HtmlInputText npt = row.FindControl( "input1 ") as HtmlInputText;
if(npt != null) Response.Write(npt.Value);
}

}

  相关解决方案