日期:2014-05-18  浏览次数:20373 次

访问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);
}

}