Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 6-Feb-17 19:10pm
v2

Add this in the loop HTML DOM Table insertRow() Method[^]
 
Share this answer
 
//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);
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900