自动创建表 [英] Create tables automatic

查看:60
本文介绍了自动创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net中使用div创建了表格,但它非常简单,因为我的网站需要100行和10列,

所以当我创建表格时,它给了我很多行HTML,

喜欢这个:





I have created table using div in asp.net, but it's very simple as my website required 100 rows and 10 columns,
so when I created the tables it gives me to many lines in the HTML,
like this:


<tr>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                </tr>
                <tr>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                </tr>
                <tr>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                    <td style="border-style: solid"> </td>
                </tr>





我的尝试:





What I have tried:

so anyone can help me if there is another way to generate the table automatically (10 columns, 100 rows)

推荐答案

你可以使用javascript来计算表格的代码,然后将其插入到该元素中。



例如,假设你有一个div这个表应该是idTableDiv,你只需要一个脚本...



You can use javascript to compute the code of the table, then insert that into that element.

for example, suppose you have a div where this table is supposed to be with id "TableDiv", all you need is a script...

var tablestring = "<table>";

for (var i = 0; i < 100; i++) {
    tablestring += "<tr>"
   
    for (var j = 0; j < 10; j++) {
        tablestring += "<td style='border-style: solid'> </td>"
    }    
    
    tablestring += "</tr>"
}

tablestring += "</table>"
document.getElementById("TableDiv").innerHTML = tablestring;





如果您愿意,您也可以在服务器端计算表格,原则相同,只有您的divTableDiv需要runat =server属性。



还有一个可以使用的ASP.Net特定的表控件,但可能需要相同javascript的一种努力(你需要计算内容) HtmlTable Class (System.Web.UI.HtmlControls) [ ^ ]


我在html中写了这样的脚本



I have write the script in the html like this

<head runat="server">
<link href="CSS/Style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
   <pre> <script type="text/javascript">
     var tablestring = "<table>";
     for (var i = 0; i < 100; i++) {
     tablestring += "<tr>"
     for (var j = 0; j < 10; j++) {
     tablestring += "<td style='border-style: solid'> </td>"
     }    
     tablestring += "</tr>"
     }
     tablestring += "</table>"
     document.getElementById("TableDiv").innerHTML = tablestring;
    </script>







然后我id = Tablediv就像这样




then i id=Tablediv like this

<div id="TableDiv">
         </div>



但不起作用


but its not working


这篇关于自动创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆