首页 新闻 会员 周边 捐助

javascript如何设置获取GridView模板列的值

0
悬赏园豆:20 [已解决问题] 解决于 2008-08-08 18:58
<P>如题。</P> <P>比如如下一个GridView&nbsp;</P><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--> <DIV class=cnblogs_code><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">asp:GridView&nbsp;</SPAN><SPAN style="COLOR: #ff0000">ID</SPAN><SPAN style="COLOR: #0000ff">="GridView1"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;runat</SPAN><SPAN style="COLOR: #0000ff">="server"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;AutoGenerateColumns</SPAN><SPAN style="COLOR: #0000ff">="False"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataKeyNames</SPAN><SPAN style="COLOR: #0000ff">="NewsID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;DataSourceID</SPAN><SPAN style="COLOR: #0000ff">="SqlDataSource1"</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">Columns</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">asp:BoundField&nbsp;</SPAN><SPAN style="COLOR: #ff0000">DataField</SPAN><SPAN style="COLOR: #0000ff">="Title"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;HeaderText</SPAN><SPAN style="COLOR: #0000ff">="Title"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;SortExpression</SPAN><SPAN style="COLOR: #0000ff">="Title"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">asp:BoundField&nbsp;</SPAN><SPAN style="COLOR: #ff0000">DataField</SPAN><SPAN style="COLOR: #0000ff">="AddTime"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;HeaderText</SPAN><SPAN style="COLOR: #0000ff">="AddTime"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SortExpression</SPAN><SPAN style="COLOR: #0000ff">="AddTime"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;&nbsp;DataFormatString</SPAN><SPAN style="COLOR: #0000ff">="{0:yyyy-MM-dd}"</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">asp:BoundField&nbsp;</SPAN><SPAN style="COLOR: #ff0000">DataField</SPAN><SPAN style="COLOR: #0000ff">="AccountID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;HeaderText</SPAN><SPAN style="COLOR: #0000ff">="AccountID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SortExpression</SPAN><SPAN style="COLOR: #0000ff">="AccountID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">asp:BoundField&nbsp;</SPAN><SPAN style="COLOR: #ff0000">DataField</SPAN><SPAN style="COLOR: #0000ff">="NewsID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;HeaderText</SPAN><SPAN style="COLOR: #0000ff">="NewsID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;InsertVisible</SPAN><SPAN style="COLOR: #0000ff">="False"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;<BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ReadOnly</SPAN><SPAN style="COLOR: #0000ff">="True"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;SortExpression</SPAN><SPAN style="COLOR: #0000ff">="NewsID"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">asp:TemplateField</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">ItemTemplate</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">asp:TextBox&nbsp;</SPAN><SPAN style="COLOR: #ff0000">ID</SPAN><SPAN style="COLOR: #0000ff">="txtbx"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;runat</SPAN><SPAN style="COLOR: #0000ff">="server"</SPAN><SPAN style="COLOR: #ff0000">&nbsp;Text</SPAN><SPAN style="COLOR: #0000ff">='&lt;%#&nbsp;</SPAN><SPAN style="COLOR: #ff0000">Eval("AccountID")&nbsp;%</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000">'&gt;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">asp:TextBox</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">ItemTemplate</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">asp:TemplateField</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">Columns</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://space.cnblogs.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">asp:GridView</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN></DIV> <DIV class=cnblogs_code><SPAN style="COLOR: #0000ff">&nbsp;</SPAN></DIV> <DIV class=cnblogs_code><SPAN style="COLOR: #0000ff">我要用javascript获取txtbx的值,然后根据这个值做些修改。用什么能实现。谢谢各位啦。</SPAN></DIV>
zeus2的主页 zeus2 | 初学一级 | 园豆:92
提问于:2008-08-08 16:13
< >
分享
最佳答案
0
如果使用html控件还好一些,服务器控件就比较郁闷一些,因为GridView生成之后是多行的,所以这个文本框也会有很多个,另一方面asp.net会自动重新命名控件,所以想通过ID获取已经不可能了,很不幸的是连name属性都被自动生成了,哪怕你添加了name属性,也无法覆盖生成的name,而是会出来两个name属性 那么就想别的办法,如果在GridView中只有一个模板列(其实是要求生成后一行只有一个input,那么可以使用下面这种办法: var txtbx = document.getElementById("<%=GridView1.ClientID%>").getElementsByTagName("input"); for(var i=0;i<txtbx.length;i++){ // txtbx[i]可以循环取出一个个文本框 } 如果有很多个,那么可以使用下面的办法: var txtbx = document.getElementById("<%=GridView1.ClientID%>").getElementsByTagName("input"); for(var i=0;i<txtbx.length;i++){ if(txtbx[i].id.indexOf("txtbx")!=-1){ // 这里的txtbx[i]就是你想要的,生成的ID里会包含你原来的ID } }
丁学 | 专家六级 |园豆:18730 | 2008-08-08 18:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册