Create a label or other control based on a database table value

I want to create a shortcut or text field based on the value of a database column. For example: I have a column value in the database table Daily Leave, Medical Leave, Annual Leave, etc. I want to create a dynamic label and corresponding text field for the above column value.

I want this control ...

         Casual Leave :  Textbox1
         Medical Leave:  Textbox2
         Annul Leave  :  Textbox3
         etc based on table value

What am I doing? I can not do it. please help me...

+5
source share
2 answers

ASP. . , ( ) .

+1

<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);
            }
+3

All Articles