How Dynamically Add Rows into ASP.NET Table using C#

Shubham
Posted by Shubham under C# category on | Points: 40 | Views : 10244
You need to first create a row and then create a cell assign the properties of cell and then add the cell to row and then row to table.
===============================================================================================================================

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ">

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc.Text = "PetsMantra.com";
tr.Cells.Add(tc);
TableCell tc2 = new TableCell();
tc2.Text = "Join2Green.com";
tr.Cells.Add(tc2);
tblSample.Rows.Add(tr);
}
</script>

<html>
<head>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:table ID="tblSample" runat="server"></asp:table>
</div>
</form>
</body>
</html>

Comments or Responses

Login to post response