How to add label control or text control in Datatable?

Hi, I have created DataTable programmatically and added below columns:
---------------------------------------------------------------------------------------------
DataColumn dtc = new DataColumn("Site Title", Type.GetType("System.String"));
dt.Columns.Add(dtc);
dtc = new DataColumn("User Name", Type.GetType("System.String"));
dt.Columns.Add(dtc);
dtc = new DataColumn("Read", Type.GetType("System.String"));
dt.Columns.Add(dtc);
--------------------------------------------------------------------------------
And created label:
------------------------------------------------------------
Label lbl = new Label();
lbl.BackColor = Color.Blue;
lbl.Text = “textbox1.text”;
-------------------------------------------------------------
Now, how to add lable in DataTable so labale color and the text value of label should display.
Means, I want to add here:
dtr["Site Title"] = “label should come here with blue color”;  //DataRow dtr;

Kindly help.
LVL 1
prdeshpandeAsked:
Who is Participating?
 
mayank_joshiCommented:
A Datatable is meant only for data.You can not add label control or textbox control to it.
But you can add their values using label.Text or TextBox.text
0
 
mayank_joshiCommented:
You may use the asp "Table" server control for adding controls.
or you may use Datatable for adding each property of a control in a separate column.
0
 
Asim NazirCommented:
Hi,

What joshi is saying is correct. On HTML side perhaps this will help:
 
<table class="style1">
        <tr>
            <td>
                <asp:Label ID="Label1" runat="server" BackColor="#0066FF" Text="Label"></asp:Label>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>

Open in new window


Asim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.