如何使用循环打印HTML表? [英] How to print HTML table using loops?

查看:332
本文介绍了如何使用循环打印HTML表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打印html表格如







ser#column1 column 2 column2

第1行

第2行

第3行



我尝试了什么:



int row = 3;

int column5;



for(int i = i< row; i ++)

{



for(int j = 0; j< column; j ++)

{



}



}

column + J

how to print html table like



ser# column1 column 2 column2
Row1
Row2
Row3

What I have tried:

int row=3;
int column5;

for(int i=i<row;i++)
{

for(int j=0;j<column;j++)
{

}

}

column+J

推荐答案

添加此项在循环中 HTML DOM表insertRow()方法 [ ^ ]
Add this in the loop HTML DOM Table insertRow() Method[^]


// 1。创建一个私有方法,它会返回一个带有html表格的sting并用你的div标签绑定你页面上的html表格。





public string GetTable()

{

int row = 3;

int column = 5;

StringBuilder sb = new StringBuilder();

sb.Append();

for(int i = 0; i);

for(int j = 0; j);

sb.Append(+ j +); //设定你的价值。

sb.Append( );

}

sb.Append();

}

sb.Append( );



返回sb.ToString();

}

====== =================================



2这段代码是在Asp.net中创建服务器控件



公共字符串GetTable()

{

int row = 3;

int column = 5;

HtmlTable table = new HtmlTable();

for(int i = 0; i< ; row; i ++)

{

HtmlTableRow tr1 = new HtmlTableRow(); //创建行

HtmlTableCell tc1 = null;

for(int j = 0; j< column; j ++)

{

tc1 = new HtmlTableCell(); //创建单元格/列

tc1.Width =50px; //指定宽度

tc1.Height =50px; //指定高度

tc1.InnerText =姓名:; //设置列值

tr1.Controls.Add(tc1);

}

table.Controls.Add(tr1); < br $> b $ b

}

}

//此方法将返回html表的服务器控件。然后你只需将该控件绑定到你的任何服务器控件上。



例如:在你的页面上选择一个面板服务器控件。

然后在那个您可以添加此表控件的ID。



喜欢:

COntorl ctrl = GetTable();

PanelID.COntrols.Add(ctrl);
//1. Crate a private method, it will return a sting with html table and bind that html table on your page with in a Div tag.


public string GetTable()
{
int row = 3;
int column = 5;
StringBuilder sb = new StringBuilder();
sb.Append("");
for (int i = 0; i ");
for (int j = 0; j ");
sb.Append("" + j + "");// Set your value.
sb.Append("");
}
sb.Append("");
}
sb.Append("");

return sb.ToString();
}
=======================================

2. This code is to create server control in Asp.net

Public string GetTable()
{
int row=3;
int column=5;
HtmlTable table = new HtmlTable();
for (int i=0;i<row;i++)
{
HtmlTableRow tr1 = new HtmlTableRow(); // Create Row
HtmlTableCell tc1=null;
for(int j=0; j<column;j++)
{
tc1 = new HtmlTableCell(); // Create Cell/Column
tc1.Width="50px";// Assign the width
tc1.Height = "50px";// Assign the height
tc1.InnerText="Name:"; // Set your column value
tr1.Controls.Add(tc1);
}
table.Controls.Add(tr1);

}
}
//This method will return a server control of html table. Then you just bind that control to your any server control.

Ex: Take one panel server control on your page.
then on that ID you can add the this table control.

Like:
COntorl ctrl=GetTable();
PanelID.COntrols.Add(ctrl);


检查这个

使用JavaScript和DOM接口创建HTML表格 [ ^ ]


这篇关于如何使用循环打印HTML表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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