In IE5 and later, significantly faster Table Rendering is now possible. Here is some information in MSDN : Enhancing Table Presentation.
Among other things, you can specific col specific widths using the colgroup tag or col tag and also set the visibility of rows and columns using special styles.
’Populate the DataSet ds
Dim dr As DataRow
For Each dc In ds.Tables(0).Columns
Dim trow As New TableRow()
Dim tcellcolname As New TableCell()
’To Display the Column Names
For Each dr In ds.Tables(0).Rows
tcellcolname.Text = dc.ColumnName
trow.BackColor = System.Drawing.Color.Beige
tcellcolname.BackColor = System.Drawing.Color.AliceBlue
’Populate the TableCell with the ColumnName
tcellcolname.Controls.Add(New LiteralControl(dc.ColumnName.ToString))
Next
trow.Cells.Add(tcellcolname)
’To Display the ColumnDataForEach dr In ds.Tables(0).Rows
Dim tcellcoldata AsNew TableCell()
’Populate the TableCell with the ColumnData
tcellcoldata.Controls.Add(New LiteralControl(dr(dc.ColumnName).ToString))
trow.Cells.Add(tcellcoldata)
Next
Table1.Rows.Add(trow)
Next
C#
//Populate the DataSet dsforeach(DataColumn dc in ds.Tables[0].Columns )
{
TableRow trow = new TableRow();
TableCell tcellcolname = new TableCell() ;
foreach(DataRow dr in ds.Tables[0].Rows )
{
tcellcolname.Text = dc.ColumnName ;
trow.BackColor = System.Drawing.Color.Beige ;
tcellcolname.BackColor = System.Drawing.Color.AliceBlue ;
//Populate the TableCell with the Column Name
tcellcolname.Controls.Add(new LiteralControl(dc.ColumnName.ToString())) ;
}
trow.Cells.Add(tcellcolname) ;
//To Display the Column Data foreach(DataRow dr in ds.Tables[0].Rows )
{
TableCell tcellcoldata =new TableCell() ;
//Populate the TableCell with the Column Data
tcellcoldata.Controls.Add(new LiteralControl(dr[dc.ColumnName].ToString())) ;
trow.Cells.Add(tcellcoldata);
}
Table1.Rows.Add(trow) ;
}
Dim mycn As SqlConnection
Dim myda As SqlDataAdapter
Dim ds As DataSet
mycn = New SqlConnection('server = localhost;uid=sa;password=;database=northwind')
myda = New SqlDataAdapter('Select Employeeid, FirstName , LastName from employees', mycn)
ds = New DataSet
myda.Fill(ds, 'Employees')
Dim dc As DataColumn
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows
Dim trow AsNew TableRow
For Each dc In ds.Tables(0).Columns
Dim tcell AsNew TableCell
tcell.Controls.Add(New LiteralControl(dr(dc.ColumnName).ToString))
trow.Cells.Add(tcell)
Next
Table1.Rows.Add(trow)
Next
C#
SqlConnection mycn ;
SqlDataAdapter myda ;
DataSet ds ;
mycn = new SqlConnection('server = localhost;uid=sa;password=;database=northwind');
myda = new SqlDataAdapter('Select Employeeid, FirstName , LastName from employees', mycn);
ds = new DataSet();
myda.Fill(ds, 'Employees');
TableRow trow ;
TableCell tcell;
foreach (DataRow dr in ds.Tables[0].Rows)
{
trow = new TableRow ();
foreach( DataColumn dc in ds.Tables[0].Columns)
{
tcell= new TableCell ();
tcell.Controls.Add(new LiteralControl(dr[dc.ColumnName].ToString()));
trow.Cells.Add(tcell);
}
Table1.Rows.Add(trow);
}