Pages

Monday, 20 February 2012

Dynamically adding Row To Table in ASP.NET(C# code)

The following code will create Rows dynamically in an ASP.NET table control,if this code is attached in a loop then that will create multiple rows,Try and enjoy the code
protected void Page_Load(object sender,EventArgs e)
{
       //Initializes new Table Row object
       TableRow tr = new TableRow( ) ;
       //Initializes new table Cell object
       TableCell fname = new TableCell( ) ;
       fname.Text = "hai" ;
       //Adds Cell to Row
       tr.Cells.Add(fname) ;
       TableCell lname = new TableCell( ) ;
       lname.Text = "how are you?" ;
       tr.Cells.Add(lname) ;
       //Adds Row to Table
       Table1.Rows.Add(tr) ;
}

No comments:

Post a Comment