如何获取GridView中html控件的值
GridView1中有个input 怎么在后台获取input的value值呢?
<input type="hidden" value="1" id="a">
下面这两种方法都获取不到值哦
HtmlInputText npt = GridView1.Rows[i].Cells[13].FindControl("a") as HtmlInputText;
if (npt != null) Response.Write(npt.Value);
foreach (GridViewRow row in GridView1.Rows)
{
HtmlInputText npt = row.FindControl("a") as HtmlInputText;
if (npt != null) Logs.FileLog(npt.Value);
}
------解决方案--------------------方法1.必须加runat=server
<input type="hidden" value="1" id="a" runat=server> 才能获取
方法2.加name属性
<input type="hidden" value="1" name=xx>
才能获取。否则是不能获取到的
------解决方案--------------------要么换成服务器控件 ,要么就加runat="server"
------解决方案--------------------HtmlInputText npt = GridView1.Rows[i].FindControl("a") as HtmlInputText