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

开了好几贴了,一直没有解决,取Table表中控件的值的有关问题

2011-12-21 
开了好几贴了,一直没有解决,取Table表中控件的值的问题以下是通过服务端代码动态生成的一个Table,我想获取

开了好几贴了,一直没有解决,取Table表中控件的值的问题
以下是通过服务端代码动态生成的一个Table,我想获取隐藏控件的值。
  (这种格式有点难搞)希望大家多多指教
  <table   id= "Table1 "   align= "center "   border= "1 "   width= "80% "   cellpadding= "0 "   cellspacing= "0 ">
<tr>
<td   colspan= "2 "   align= "center "   width= "50% "   style= "height:   22px "> 项目 </td>
<td   align= "center "   width= "30% "   style= "height:   22px "> 数量 </td>
</tr>
<tr>
<td   rowspan= "6 "   align= "center "> 工作覆盖面 </td>
</tr>
<tr>
<td> 辖区人口总数 <input   name= "hidden7 "   type= "hidden "   id= "hidden7 "   value= "7 "   /> </td>
<td   align= "center "> <input   name= "0 "   type= "text "   value= "0 "   id= "0 "   runat= "server "   /> </td>
</tr>
<tr>
<td> 辖区街道数 <input   name= "hidden8 "   type= "hidden "   id= "hidden8 "   value= "8 "   /> </td>
<td   align= "center "> <input   name= "1 "   type= "text "   value= "0 "   id= "1 "   /> </td>
</tr>
<tr>
<td> 辖区乡镇数 <input   name= "hidden9 "   type= "hidden "   id= "hidden9 "   value= "9 "   /> </td>
<td   align= "center "> <input   name= "2 "   type= "text "   value= "0 "   id= "2 "   /> </td>
</tr>
<tr>
<td> 工作覆盖面人口数 <input   name= "hidden10 "   type= "hidden "   id= "hidden10 "   value= "10 "   /> </td>
<td   align= "center "> <input   name= "3 "   type= "text "   value= "0 "   id= "3 "   /> </td>
</tr>
<tr>
<td> 覆盖率% <input   name= "hidden11 "   type= "hidden "   id= "hidden11 "   value= "11 "   /> </td>
<td   align= "center "> <input   name= "4 "   type= "text "   value= "0 "   id= "4 "   /> </td>
</tr>
<tr>
<td   rowspan= "5 "   align= "center "> 监护网服务 </td>
</tr>
<tr>
<td> 监护居(村)委会数 <input   name= "hidden12 "   type= "hidden "   id= "hidden12 "   value= "12 "   /> </td>
<td   align= "center "> <input   name= "0 "   type= "text "   value= "0 "   id= "0 "   /> </td>
</tr>
<tr>
<td> 监护病人数 <input   name= "hidden13 "   type= "hidden "   id= "hidden13 "   value= "13 "   /> </td>
<td   align= "center "> <input   name= "1 "   type= "text "   value= "0 "   id= "1 "   /> </td>


</tr>
<tr>
<td> 监护率% <input   name= "hidden14 "   type= "hidden "   id= "hidden14 "   value= "14 "   /> </td>
<td   align= "center "> <input   name= "2 "   type= "text "   value= "0 "   id= "2 "   /> </td>
</tr>
<tr>
<td> 一级管理病人数 <input   name= "hidden15 "   type= "hidden "   id= "hidden15 "   value= "15 "   /> </td>
<td   align= "center "> <input   name= "3 "   type= "text "   value= "0 "   id= "3 "   /> </td>
</tr>
</table>

[解决办法]
Request.Form[ "1 "] 但是你的hidden的name很多重名了. 要注意
[解决办法]
不如用asp下常用的方法,把所有要取值的hidden控件的name属性都设成相同的,比如

<input name=h id= "Hidden2 " type= "hidden " value=10 />
<input name=h id= "Hidden3 " type= "hidden " value=20 />

然后在后台取Request.Form[ "h "]的值,可以取得一个字符串值 "10,20 ",剩下的自己去处理把
[解决办法]
每个隐藏的控件加一个runat= "server "

改成这样:
<td> 辖区人口总数 <input name= "hidden7 " type= "hidden " id= "hidden7 " value= "7 " runat= "server " /> </td>

然后.cs代码里写
string txtStr=hidden7.value;

就能取到hidden7的值了,其他的也这样做就可以了!
[解决办法]
将控件的类型名字转换成字符串进行比对
[解决办法]
最最直接的方法
把所有的隐藏控件都换成web控件asp:textbox 加上样式style= "display:none; "
然后直接就可在后台通过控件ID取值了
[解决办法]
table 是在cs生成的,是用什么形式生成的?添加控件?还是输出string?如果添加控件,postback需要重新绑定。然后使用FindControl()....
[解决办法]
//加入隐藏控件保存项目编码的值
HtmlInputHidden hidden2 = new HtmlInputHidden();
hidden2.ID = "hidden " + colds.Tables[0].Rows[j][0].ToString();
hidden2.Value = colds.Tables[0].Rows[j][0].ToString();
//替换
TextBox txtHidden = new TextBox();
txtHidden.Attributes.add( "style ", "display:none; ");
txtHidden.ID = "hidden " + colds.Tables[0].Rows[j][0].ToString();
txtHidden.Value = colds.Tables[0].Rows[j][0].ToString();


//取值
循环表行,((TextBox)tr.FindControls[0]).Text就是想获取的值

[解决办法]
用 Table试试看,不要用HtmlTable...
[解决办法]
标记

热点排行