asp.net自动添加文本框或dropdownlist

发布时间:2020-01-28编辑:脚本学堂
本文介绍了asp.net自动添加文本框或dropdownlist的实例代码,有需要的朋友参考下。

1,asp.net 前台js代码:
 

复制代码 代码示例:

<script type="text/javascript">
     function AddInputArea() {
         var div = document.createElement("<div>");
         div.innerHTML = "<table id='TbForm'><tr><td>查询对象</td><td><select name='select'><option value=''>请选择</option><option value='Ip'>Ip</option><option value='Type'>设备类型</option><option value='Fixed_Assets'>固定资产</option><option value='Mac_Address'>mac地址</option><option value='Internet'>Internet</option><option value='Chinese_OS'>中文OS</option><option value='Chinese_Win'>中文Win</option><option value='Chinese_Office'>中文Office</option><option value='Kingsoft'>金山词霸</option><option value='Acdsee'>Acdsee</option><option value='Win_Rar'>Win_Rar</option><option value='Jinpan_Win'>日文Win</option><option value='Jinpan_Office'>日文Office</option><option value='Jinpan_OS'>日文OS</option><option value='Jacdsee'>日文adcsee</option><option value='Jwinrar'>日文winrar</option><option value='Autocad'>Autocad</option><option value='SQL_Database'>SQL数据库</option><option value='Adobe_Acrobat'>采购日期</option><option value='VS'>VS</option><option value='Warranty_Time'>保修期限</option><option value='Device_Use'>设备用途</option><option value='Device_Name'>设备名称</option><option value='Storage_Location'>存储位置</option><option value='Acquired_Date'>采购日期</option><option value='a.Departments_ID'>使用部门</option><option value='User'>使用者</option><option value='Machine_Id'>机器名称</option><option value='Sts_Info'>使用情况</option><option value='Device_Info'>设备信息</option><option value='Assert_Sn'>资产编号</option></select></td><td>条件</td><td><select name='inputName'><option value=''>请选择</option><option value='='>等于</option><option value='>'>大于</option><option value='<'>小于</option><option value='!='>不等于</option><option value='>='>大于等于</option><option value='<='>小于等于</option><option value='LIKE%'>模糊匹配</option></select></td><td>查询内容</td><td><input name='inputSum' type='text'/></td><td>并列条件</td><td><select name='inputCondition'><option value=' '>请选择</option><option value='OR'>或者</option><option value='AND'>并且</option><select></td></tr></table>";
         document.getElementById("Content").appendChild(div);
        
     }
     function GetAddInput() {

         var strSql = "";
         var names = document.getElementsByName("inputName");
         var select = document.getElementsByName("select");
         var inputCondition = document.getElementsByName("inputCondition");
         if (names.length == 0) {
             alert("没有可用的信息!");
             return false;
         }
         var genders = document.getElementsByName("inputSum");

         for (var i = 0; i < names.length; i++) {

            if (select[i].value=="")
            {
                alert("查询对象不能为空!");
                break;
            }
            if (names[i].value == "") {
                alert("条件不能为空!");
                break;
            }
            if (genders[i].value == "") {
                alert("内容不能为空!");
                break;
            }
           
            strSql += "(" + select[i].value + " " + names[i].value + " " + "'"+genders[i].value+"'" + ")" + " " + inputCondition[i].value;
          
         }
         document.getElementById("hf_Sql").value = strSql;
     }      
  </script>

2,html代码: 
   

复制代码 代码示例:
<html>
       <head>
       </head>
       <body> 
          <div id="Content">
          </div>
          <asp:HiddenField  ID="hf_Sql" runat="server" />
          <asp:Label ID="lbSql" runat="server"></asp:Label>
       </body>
    </html>

3,后台代码
 

复制代码 代码示例:
string strSql = hf_Sql.Value; 
hbSql.text=   strSql ;