当前位置:编程学习 > C#/ASP.NET >>

求教个前台循环table 的问题

前台页面:
<table>
<tr>
<td>姓名:</td>
<td>  <asp:TextBox runat="server" ID="xm"></asp:TextBox>  </td>
</tr>
<tr>
<td>性别:</td>
<td>  <asp:TextBox runat="server" ID="xb"></asp:TextBox>  </td>
</tr>
</table>

假如我数据库是“
test表      
 ID  XM    XB
 1   张三   男
 2   李四    男



在前台页面上就一个table 的情况下,,,循环 test表里面的两条数据,,把前台的table  显示出来两份,分别显示  test表 的 两条数据 ASP --------------------编程问答--------------------     <asp:Repeater ID="rp_datalist" runat="server">
        <ItemTemplate>
            <table>
                <tr>
                    <td>
                        姓名:
                    </td>
                    <td>
                        <asp:TextBox runat="server" ID="xm" Text='<%# Eval("xm") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        性别:
                    </td>
                    <td>
                        <asp:TextBox runat="server" ID="xb" Text='<%# Eval("xb") %>'></asp:TextBox>
                    </td>
                </tr>
            </table>
        </ItemTemplate>
    </asp:Repeater>

后台直接把DataTable给Repeater --------------------编程问答-------------------- 不要用 Repeater  ,我要把前台的 table  循环出两个 table 分别装入 test 里面的两条数据,


<table>
<tr>
<td>姓名:</td>
<td>  张三 </td>
</tr>
<tr>
<td>性别:</td>
<td>  男  </td>
</tr>
</table>


<table>
<tr>
<td>姓名:</td>
<td> 李四 </td>
</tr>
<tr>
<td>性别:</td>
<td>  男  </td>
</tr>
</table>

要这样的效果~ --------------------编程问答-------------------- 把两条数据都塞入两个表格中,用DataTabel给GradView呗 --------------------编程问答-------------------- 在cs内循环产生,然后动态添加至网页中去:
如:
http://www.cnblogs.com/insus/archive/2012/10/29/2744721.html --------------------编程问答-------------------- 这个也不错的参考喔:
http://www.cnblogs.com/insus/archive/2013/04/26/3045046.html --------------------编程问答--------------------
引用 2 楼 xx19890213 的回复:
不要用 Repeater  ,我要把前台的 table  循环出两个 table 分别装入 test 里面的两条数据,


<table>
<tr>
<td>姓名:</td>
<td>  张三 </td>
</tr>
<tr>
<td>性别:</td>
<td>  男  </td>
</tr>
</table>


<table>
<tr>
<td>姓名:</td>
<td> 李四 </td>
</tr>
<tr>
<td>性别:</td>
<td>  男  </td>
</tr>
</table>

要这样的效果~

页面就不要table,直接用个div,然后再后台动态构造table,用StringBuilder
类似这种

StringBuilder sb = new StringBuilder();
sb.Append("<table id=\"tblbrd\" class=\"thin sortable\"  align=\"left\" cellpadding=\"0\" cellspacing=\"0\"  style=\"font-size: 12px; height:10%; border-collapse: collapse; font-weight:bold;table-layout:fixed; word-break:break-all\" bgcolor=\"#7DB0AA\" width=\"200%\">");
        sb.Append("<tr class=\"FixedTitleRow\" bgcolor=\"#7DB0AA\">");
        sb.Append("<td class=\"FixedDataColumn\" align=\"center\" style=\"width: 6%;height:24px\">姓名</td>");
sb.Append("<td class=\"FixedDataColumn\" align=\"center\" style=\"width: 6%;height:24px\">性别</td>");
        sb.Append("</tr>>");
        sb.Append("</table>>");

构造好后,把table赋给div.InnerHtml --------------------编程问答-------------------- 我是前台的页面已经存在,,表格很复杂,不能写到后台去,,怎么在前台的table 存在的情况下,不在后面画表格,来实现呢? --------------------编程问答--------------------
引用 6 楼 Chinajiyong 的回复:
Quote: 引用 2 楼 xx19890213 的回复:

不要用 Repeater  ,我要把前台的 table  循环出两个 table 分别装入 test 里面的两条数据,


<table>
<tr>
<td>姓名:</td>
<td>  张三 </td>
</tr>
<tr>
<td>性别:</td>
<td>  男  </td>
</tr>
</table>


<table>
<tr>
<td>姓名:</td>
<td> 李四 </td>
</tr>
<tr>
<td>性别:</td>
<td>  男  </td>
</tr>
</table>

要这样的效果~

页面就不要table,直接用个div,然后再后台动态构造table,用StringBuilder
类似这种

StringBuilder sb = new StringBuilder();
sb.Append("<table id=\"tblbrd\" class=\"thin sortable\"  align=\"left\" cellpadding=\"0\" cellspacing=\"0\"  style=\"font-size: 12px; height:10%; border-collapse: collapse; font-weight:bold;table-layout:fixed; word-break:break-all\" bgcolor=\"#7DB0AA\" width=\"200%\">");
        sb.Append("<tr class=\"FixedTitleRow\" bgcolor=\"#7DB0AA\">");
        sb.Append("<td class=\"FixedDataColumn\" align=\"center\" style=\"width: 6%;height:24px\">姓名</td>");
sb.Append("<td class=\"FixedDataColumn\" align=\"center\" style=\"width: 6%;height:24px\">性别</td>");
        sb.Append("</tr>>");
        sb.Append("</table>>");

构造好后,把table赋给div.InnerHtml




我是前台的页面已经存在,,表格很复杂,不能写到后台去,,怎么在前台的table 存在的情况下,不在后面画表格,来实现呢? --------------------编程问答--------------------
引用 6 楼 Chinajiyong 的回复:
Quote: 引用 2 楼 xx19890213 的回复:

不要用 Repeater  ,我要把前台的 table  循环出两个 table 分别装入 test 里面的两条数据,


<table>
<tr>
<td>姓名:</td>
<td>  张三 </td>
</tr>
<tr>
<td>性别:</td>
<td>  男  </td>
</tr>
</table>


<table>
<tr>
<td>姓名:</td>
<td> 李四 </td>
</tr>
<tr>
<td>性别:</td>
<td>  男  </td>
</tr>
</table>

要这样的效果~

页面就不要table,直接用个div,然后再后台动态构造table,用StringBuilder
类似这种

StringBuilder sb = new StringBuilder();
sb.Append("<table id=\"tblbrd\" class=\"thin sortable\"  align=\"left\" cellpadding=\"0\" cellspacing=\"0\"  style=\"font-size: 12px; height:10%; border-collapse: collapse; font-weight:bold;table-layout:fixed; word-break:break-all\" bgcolor=\"#7DB0AA\" width=\"200%\">");
        sb.Append("<tr class=\"FixedTitleRow\" bgcolor=\"#7DB0AA\">");
        sb.Append("<td class=\"FixedDataColumn\" align=\"center\" style=\"width: 6%;height:24px\">姓名</td>");
sb.Append("<td class=\"FixedDataColumn\" align=\"center\" style=\"width: 6%;height:24px\">性别</td>");
        sb.Append("</tr>>");
        sb.Append("</table>>");

构造好后,把table赋给div.InnerHtml
+10086 --------------------编程问答-------------------- datalist超帅气了,你试试,有几条数据给你遍历出多少个table --------------------编程问答-------------------- 楼主是要在js里面实现吧! 前台或后台拼你的html字符串都可以啊 --------------------编程问答--------------------   <% foreach ()
    {
  <table> 
   <tr>
            <td align="center">
            姓名:<%=name%>
           </td>
  </tr>
  </table>
<% }%> --------------------编程问答-------------------- 后台返回json数据,前台遍历循环拼html就好 --------------------编程问答-------------------- 来学习的 --------------------编程问答-------------------- 参考
http://bbs.csdn.net/topics/390453061

//这个是最终模式
     <script runat="server">
        public int i = 0;//这里可以放置读取数据库的代码
    </script>
    <%for (i = 0; i < 3; i++)
      {%>
    <% datalist.ID = datalist.ID + "_" + i.ToString(); %>
    <div id="datalist" runat="server">
        <% Response.Write(i.ToString()); %></div>
    <%}%>
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,