c#中怎么在指定表格中插入一行
网页中有个表格
我想用c#语句在那表格中插入一行 
怎么写
有没有人知道
谢谢了

解决方案 »

  1.   

    這樣的操作一般采用javascript來實現的
      

  2.   

    每个单元格定义成服务器控件,然后一个个的赋值,诸如:td1=sdr["name"].tostring(),td2=sdr["sex"].ToString()等等....可以吗?
      

  3.   

    什么表格?用的是服务器控件的Table 
    就用:
    TableRow tRow = new TableRow();
    Table1.Rows.Add(tRow);
      

  4.   

    我现在用js做的
    现在我还有个问题想问问
    关于js的判断方面
    要验证的是判断用户输入的查询条件是否有单引号
    判断括号是否完整,有没有多余的逻辑
    不知道怎么写
    有没有人可以帮帮我
     代码如下:
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
        <script language="JavaScript" type="text/javascript">
         function addQueryTable() 
        {
            var   row1 = queryTable.insertRow();  //插入一行  
            var   cell1=row1.insertCell();   
            var   cell2=row1.insertCell();   
            var   cell3=row1.insertCell();   
            var   cell4=row1.insertCell();   
            var   cell5=row1.insertCell();   
            var   cell6=row1.insertCell();   
            var   cell7=row1.insertCell();   
            var len = window.queryTable.rows.length
            var logicConn ="<select name=col7"+len+"  onChange='addQueryTable()' ><option value='' selected=selected>"+
                           "连接符...</option><option value=' AND '>并且</option><option value=' OR '>或者</option></select>" 
            var logicComp = "<select name=col6"+len+"  ><option value=' = ' selected=selected>等于</option>"+
                          "<option value=' > '>大于</option><option value=' < '>小于</option><option value=' = '>"+
                          "等于</option><option value=' <> '>不等于</option><option value=' like '>匹配</option>"+
                          "<option value=' is null '>为空</option><option value=' is not null '>非空</option><option "+
                          "value=' in '>包含</option><option value=' not in '>不包含</option></select>"
            cell1.innerHTML =  "<td align='left' width='8%'><input   type='text' name='col1"+len+"' size=11 value='('></td>";  //左括号
             var tmpSelect = "<select name=col2"+len+"  ><option value=' n_id ' selected=selected>编号</option>"+
                          "<option value=' n_title '>标题</option><option value=' n_content '>内容</option><option value=' n_type '>"+
                          "类型</option></select>"
               
                                            
            cell2.innerHTML = "<td align='left' width='20%'>" + tmpSelect +"</td>"  ;
            cell3.innerHTML =  "<td align='left' width='10%'>"+logicComp+"</td>";  //逻辑运算符
            cell4.innerHTML =  "<td align='right' width='12%'><input   type='text'   name='col4"+len+"' size=12  value=\""+"'"+"\"></td>"; 
            cell5.innerHTML =  "<td class='add_content_' width='40%'><input   type='text'   name='col5"+len+"' size=12  value=\"\"></td>"  //查询条件值
          
            cell6.innerHTML =  "<td align='left' width='8%'> <input   type='text'   name='col16"+len+"' size=8 value=\""+"')"+"\"></td>";  // 括号
            cell7.innerHTML =  "<td align='left' width='8%'>"+logicConn+"</td>";  //逻辑连接符ect>" 
          
           
        } 
         //获得设置的查询条件
        function   getCondition( )
        {   
            //alert(window.tb1.rows.length);表格的长度
            //   alert(document.test.a1. value)   
            // alert(document.test.conditionCol1 . value)        
            //获得标签的名字  循环a[i].value  肯定能行
         //   alert( document.test.getElementsByTagName('input')[1].value)
            // alert( document.test.getElementsByTagName('select')[0].value)
             var len = window.queryTable.rows.length
                  //alert(window.queryTable.getElementsByName('col1').value)
             //alert(window.queryTable.getElementsByTagName('input')[0].value)
             var queryString ="";
             for(i=0;i<len;i++)
             {
                var col1 = window.queryTable.getElementsByTagName('input')[i*4+0].value   //左括号
                if(col1==null||col1=='null')col1=""
               
                var col2 = window.queryTable.getElementsByTagName('select')[i*3+0].value  //获得查询字段名
                if(col2==null||col2=='null')col2=""
               
                var col3 = window.queryTable.getElementsByTagName('select')[i*3+1].value  //获得逻辑比较符
                if(col3==null||col3=='null')col3=""
                var col4 = window.queryTable.getElementsByTagName('input')[i*4+1].value   //括号
                if(col14=null||col4=='null')col4=""
                var col5 = window.queryTable.getElementsByTagName('input')[i*4+2].value     
                if(col5==null||col5=='null')col5=""  
                col5=
                   
                 
                //col5="\'"+col5+"\'"
               // alert(col5)
                var col6 = window.queryTable.getElementsByTagName('input')[i*4+3].value   //括号
                if(col6==null||col6=='null')col6=""
                var col7 = window.queryTable.getElementsByTagName('select')[i*3+2].value  //获得逻辑连接符
                if(col3==' like ')col5='%'+col5+'%'  //如果是模糊查询,自动增加%
                if(col3==' is null '||col3==' is not null ')col5="";  //如果设置了is null和is not null表达式,则后面不需要条件值
                if(col3==' is null '||col3==' is not null ')col4="";
                if(col3==' is null '||col3==' is not null ')col6=")";
                if(col7==null||col7=='null')col7=""
                //alert(col5)
                if(col2==null||col2==""||col2=='null')
                {
                    //如果col2为空,不再计算条件表达式
                     
                    break;
                }
                
                queryString += col1+col2+col3+col4+col5+col6+col7
                        }
           alert(queryString)
           window.returnValue   =queryString; 
      //window.close();     }    
    -->
     </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <table  width="96%" align="center" class="all"> 
    <tr class="allcontent">
    <td class="allcontent">
    <fieldset>   <legend></legend>
      <table width="100%" border="0" align="center" cellpadding="2" cellspacing="0" class="query"> 
     <tr class="query_content_"> 
     
      <td colspan="4" class="query_content_"  align="right"> 
     
    <input type="button"  value="新增" onClick="addQueryTable()" class="mybutton">
    <input type="button"  value="执行查询" onClick="getCondition()" class="mybutton">
                                 </tr>
    </table>
    </fieldset>
    <fieldset>
    <legend>查询条件设置</legend>
    <table width="100%" class="result"  border="1" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
        <tr id="docktr" align="center" class="result_title">
        <td nowrap class="result_head_dock" width="10%">括号</td>
        <td nowrap class="result_head_dock" width="20%"  >查询条件列</td>
        <td nowrap class="result_head_dock" width="10%">逻辑运算符</td>
        <td nowrap class="result_head_dock" width="10%">括号</td>
        <td nowrap class="result_head_dock" width="30%">查询条件值</td>
        <td nowrap class="result_head_dock" width="10%">括号</td>
        <td nowrap class="result_head_dock" width="10%">逻辑连接符</td>
        </tr>
    </table> <div id="FixHeadContainer" style="HEIGHT: 295px;overflow=auto;">
           <table width="100%"><tr><td>
           <table width="100%" class="result" id="queryTable"  border="1" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> 
         </table>
    <script Language="Javascript1.2">
     for (i=0;i<queryTable.rows.length;i++) {
     (i%2==0)?(table1.rows(i).className = "result_content"):(table1.rows(i).className = "result_content_");
     }
    document.title="组合查询条件设置";
      addQueryTable() ;</script> 
     </td></tr>
     
    </table>
     </div>
    <table width="100%" class="resbutton">
    <tr class="resbutton">
    </tr>
    </table>  
    </fieldset>   </td>
     </tr>
    </table>    </div>
        </form>
    </body>
    </html>
      

  5.   

    如果是服务器端的Table,直接调用方法就可以
    如果是普通的Table,那可就麻烦啦 
      

  6.   

    什么表格?用的是服务器控件的Table  
    就用: 
    TableRow tRow = new TableRow(); 
    Table1.Rows.Add(tRow); 不然就只能使用DOM了