How to implement Tables in ASP.NET
When it comes to the repetitive items, Microsoft’s ASP.NET encourages you to use one of the followings controls: DataGrids, DataLists, or Repeaters. While DataGrid and DataList Controls are the easiest for displaying/editing database tables, the Repeater Controls provide the best flexibility among the three. All three of them needs to use Data Binding to bind with the database or the data source. They are all powerful, but they are not as flexible as it used to be when we were using tables in ASP.
What if we want to use the good old ASP ways to present a table under ASP.NET. The good old way is to use a While Loop to draw one cell, and then one row at a time, until the whole table is drawn. Yes, ASP.NET does include a server control called Table to allow us to add one cell, then one row at a time in a while loop.
Below is the code segment to show you how to add one row of data to the ASP.NET Table control with the ID of Table1:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
TableRow r = new TableRow();
// build the title row
TableCell c = new TableCell();
c.CssClass = "ItemSubHead";
c.BackColor = Color.BurlyWood;
c.Text="League";
c.Width = 225;
r.Cells.Add(c);
c = new TableCell();
c.CssClass = "ItemSubHead";
c.BackColor = Color.BurlyWood;
c.Text="Date";
c.Width = 180;
r.Cells.Add(c);
c = new TableCell();
c.CssClass = "ItemSubHead";
c.BackColor = Color.BurlyWood;
c.Text="Time";
c.Width = 180;
r.Cells.Add(c);
Table1.Rows.Add(r);
}

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home