Dynamic Table Create C# with CSS and aspx Page:
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
String Select;int Count;
Page Load :
protected void Page_Load(object sender, EventArgs e)
{
Select = "Select * From Registration";
da = new SqlDataAdapter(Select, Conn);
da.Fill(ds);
Count = ds.Tables[0].Rows.Count;
Table Create:
Table tbldynamic = new Table();
tbldynamic.CssClass = "tbl"; - - - >CSS
for (int i = 0; i < Count; i++)
{
TableCell tc = new TableCell();
TableRow tr = new TableRow();
TableCell tc1 = new TableCell();
tr.Height = 20;
Label lblID = new Label();
TextBox txtName = new TextBox();
lblID.Height = 20;
lblID.ID = ds.Tables[0].Rows[i]["ID"].ToString();
tc.Controls.Add(lblID);
Label lblName = new Label();
lblName.ID = "lblName" + i;
lblName.Text = ds.Tables[0].Rows[i]["Question"].ToString();
lblName.CssClass = "lbl"; - - - >Label CSS
tc.Controls.Add(lblName);
txtName.ID = "txtName" + i;
txtName.Height = 25;
txtName.CssClass = "txt"; - - - >Text Box CSS
txtName.Width = 300;
tc1.Controls.Add(txtName);
tr.Cells.Add(tc);
tr.Cells.Add(tc1);
tbldynamic.Rows.Add(tr);
tc = new TableCell();
tc1 = new TableCell();
tr = new TableRow();
tbldynamic.Rows.Add(tr);
pnl.Controls.Add(tbldynamic);
}
pnl.Controls.Add(tbldynamic);
}
aspx:
<div class="head">
Dynamic Table Creater:
</div>
<br />
<asp:Panel ID="pnl" runat="server">
</asp:Panel>
<br />
<asp:ImageButton ID="btnSave" runat="server" ImageUrl="save.png"/>
</div>
CSS Style:
<style type="text/css">
.lbl
{
font-family: Verdana;
font-size: 15px;
}
.txt
{
width: 250px;
color: Black;
height: 20px;
border: solid 1px #d1c7ac;
padding: 4px 8px;
margin-bottom: 0px;
}
.tbl
{
background-color: #E8E8E8;
}
.head
{
font-family: Verdana;
font-size: x-large;
font-weight: bold;
color: #976ea4;
}
</style>
Screen Shot:
No comments:
Post a Comment