create run time table in asp.net?

Sagarp
Posted by Sagarp under ASP.NET category on | Views : 5475
<%@ Page language="c#" Codebehind="Table.aspx.cs" AutoEventWireup="false" Inherits="day8.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body bgColor="#33ffff" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Table id="Table1" style="Z-INDEX: 101; LEFT: 152px; POSITION: absolute; TOP: 72px" runat="server"
Height="24px" GridLines="Both">
<asp:TableRow>
<asp:TableCell Text="NAME"></asp:TableCell>
<asp:TableCell Text="ADDRESS"></asp:TableCell>
<asp:TableCell Text="DEPT"></asp:TableCell>
<asp:TableCell Text="SALARY"></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Text="john"></asp:TableCell>
<asp:TableCell Text="pune"></asp:TableCell>
<asp:TableCell Text="COMP"></asp:TableCell>
<asp:TableCell Text="10,000"></asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:AdRotator id="AdRotator1" style="Z-INDEX: 107; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server"
Height="24px" BackColor="White" Width="88px" AdvertisementFile="X.xml"></asp:AdRotator>
<asp:Label id="Label2" style="Z-INDEX: 106; LEFT: 272px; POSITION: absolute; TOP: 160px" runat="server"
ForeColor="Red" Font-Bold="True">COLUMN</asp:Label>
<asp:Label id="Label1" style="Z-INDEX: 105; LEFT: 184px; POSITION: absolute; TOP: 160px" runat="server"
ForeColor="Red" Font-Bold="True">ROW</asp:Label>
<asp:Button id="Button1" style="Z-INDEX: 104; LEFT: 368px; POSITION: absolute; TOP: 184px" runat="server"
Text="CLICKE ME" ForeColor="Purple" BackColor="#FF8000"></asp:Button>
<asp:DropDownList id="DropDownList2" style="Z-INDEX: 103; LEFT: 184px; POSITION: absolute; TOP: 192px"
runat="server" AutoPostBack="True">
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 102; LEFT: 280px; POSITION: absolute; TOP: 192px"
runat="server" AutoPostBack="True">
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
</asp:DropDownList></form>
</body>
</HTML>
Table.aspx.cs
private void Button1_Click(object sender, System.EventArgs e)
{
int r,c,i,j;
r=Convert.ToInt32(this.DropDownList2.SelectedItem.Text);
c=Convert.ToInt32(this.DropDownList1.SelectedItem.Text);
for(i=0;i<=r;i++)
{
TableRow tr=new TableRow();
for(j=0;j<c;j++)
{
TableCell tc=new TableCell();
tc.Controls.Add(new LiteralControl("sagar"));


tr.Controls.Add(tc);
this.Table1.Rows.Add(tr);
}
}
}

Comments or Responses

Login to post response