用的平台是vs2005,动态生成文本框可以实现了。但是怎么来获取文本框的值呢?这是我写的html代码。
我要是生成三行的文本框,点击下一步。这九个文本框的值存到数据库中,但是这些文本框的值如何取到呢?????谢谢谢谢。
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="left">
        <table style="width: 493px; border-right: black thin solid; border-top: black thin solid; border-left: black thin solid; border-bottom: black thin solid;">
            <tr>
                <td align="center" style="width: 100px">
                    样例下载</td>
            </tr>
        </table>
        <table id="tb" style="width: 493px; height: 126px; border-right: black thin solid; border-top: black thin solid; border-left: black thin solid; border-bottom: black thin solid;">
            
            <tr>
                <td align="center" style="width: 57px">
                    <asp:Label ID="Label1" runat="server" Text="产品样例名称" Width="134px"></asp:Label></td>
                <td align="center" style="width: 100px">
                    <asp:Label ID="Label2" runat="server" Height="17px" Text="样例图片名称" Width="121px"></asp:Label></td>
                <td align="center" style="width: 99px">
                    <asp:Label ID="Label3" runat="server" Text="样例下载目录" Width="125px"></asp:Label></td>
            </tr>
            <tr>
                <td align="center" style="width: 57px">
                    <asp:TextBox ID="txtSname" runat="server" Height="18px"  Width="125px"></asp:TextBox></td>
                <td align="center" style="width: 100px">
                    <asp:TextBox ID="txtSpname" runat="server" Height="18px"  Width="125px"></asp:TextBox></td>
                <td align="center" style="width: 99px">
                    <asp:TextBox ID="txtSpath" runat="server" Height="18px" Width="125px"></asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 57px">
                    <input class="button" name="button" onclick='additem("tb")' type="button" value="添加" /></td>
                <td style="width: 100px">
                    <asp:Button ID="btnnext" runat="server" Text="下一步" Width="67px" OnClientClick="getsub()" OnClick="btnnext_Click" />
                </td>
                <td style="width: 100px">
                    <asp:Button ID="btnCancel" runat="server" Text="取消" Width="67px" /></td>
            </tr>
        </table>
    
    </div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;
        <asp:HiddenField ID="hd1" runat="server" />
    </form>
     <script language="javascript" type="text/javascript">var count=0 ;
function additem(id)
{
  var row,cell,str;
  row = document.getElementById(id).insertRow(count+1);
  if(row != null )
  {
        row.insertCell(0).innerHTML="<td><input style=\"width:125px\" id=\"St"+count+"\" type=\"text\" name=\"St"+count+"\"> </td>";
        row.insertCell(1).innerHTML="<td><input style=\"width:125px\" id=\"St"+count+"\" type=\"text\" name=\"St"+count+"\"> </td>";
        row.insertCell(2).innerHTML="<td><input style=\"width:125px\" id=\"St"+count+"\" type=\"text\" name=\"St"+count+"\"><input type=\"button\" class=\"button\" value=\"删除\" onclick=\'deleteitem(this,"+'"'+"tb"+'"'+");\'> </td>";
        count ++;     
  }
  hd1.value=count;
}
function deleteitem(obj,id)
{
        var rowNum,curRow;
        curRow = obj.parentNode.parentNode;
        rowNum = eval("document.all."+id).rows.length - 1;
        eval("document.all["+'"'+id+'"'+"]").deleteRow(curRow.rowIndex);
        count=0;
}function getsub()
{
var re="";
for (var  i = 0 ;i<count;i++)
{
re += document.getElementsByName("St"+i)[0].value+"</br>";}
document.getElementById("Hidvalue").value=re;
}    </script></body>
</html>

解决方案 »

  1.   

    一般动态生成的控件名称都是特定的,可以用
    Request.Form("控件名") 来获取││博客空间:http://blog.csdn.net/lovingkiss
    ││资源下载:http://download.csdn.net/user/lovingkiss
    ││Email:loving-kiss@163.com [MSN也是这个]
    ││联系方式:Q66840199 项目、聊天、咨询、探讨、统统收费,呵呵......
    ╚---------------------------------------------------------------------------------------------------------ō*︻$▅▆▇◤ 
      

  2.   

    Id可以用一样的,形成数组,用js控制;
    但是name不推荐这么做;
      

  3.   

    使用Request.Form["文本框name"] 可以得到值
      

  4.   

    名字命名成一样的,request.form取数组
      

  5.   

    WEB的不清楚,Form程序下我是在动态创建文本框的时候给他们name 赋值比如textbox1~9
    回头取值肯定也是有规律的,根据控件的名字遍历foreach一下就好了
      

  6.   

    能写详细点吗?我刚学。net,有些东东还不清楚
    是在button_click下面写吗?