I want to create a label or textbox based on database column value.. For example: I have a database table column value Casual Leave,Medical Leave,Annual leave,etc.. I want to create dynamic label and corresponding textbox for the above column value.
I want the control like this..
Casual Leave : Textbox1
Medical Leave: Textbox2
Annul Leave : Textbox3
etc based on table value
what i do? I can't do this. please help me...
Try this
<asp:Panel Id="pnl" runat ="server">
</asp:Panel>
Label lblT = null;
TextBox txt = null;
Table tb = new Table();
pnl.Controls.Add(tb);
DataTable table = DT_GeneratedOp();
foreach (DataColumn dr in table.Columns)
{
TableRow tr = new TableRow();
TableCell tc = new TableCell();
TableCell tc2 = new TableCell();
lblT = new Label();
txt = new TextBox();
lblT.Text = dr.ColumnName + ":";
txt.Text = table.Rows[0][dr].ToString();
tc.Controls.Add(lblT);
tc2.Controls.Add(txt);
tr.Cells.Add(tc);
tr.Cells.Add(tc2);
tb.Rows.Add(tr);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With