0

I am working on a dynamic asp.net page, and ı generate some label and text box in my form page. But ı want to generate them in the specific div class. How can ı solve that problem?


Here is codes:

for (int i = 0; i < countStart; i++)    //Create all content of the table in here
{
    //CREATE ALL LABELS
    Label lbl = new Label();
    string colName = ds1.Tables[0].Rows[i]["COLUMN_NAME"].ToString();  //SET LABEL NAME LİKE TABLE COLUMN NAME
    lbl.Text = colName;
    lbl.ID = "lbl" + ds1.Tables[0].Rows[i]["COLUMN_NAME"].ToString() + i.ToString(); //SET LABEL ID LİKE TABLE COLUMN NAME PLUS İNT İ VALUE

    form1.Controls.Add(lbl);

    Label space = new Label(); space.Text = "                  "; form1.Controls.Add(space);  //SPACE 

    //CREATE ALL TEXT BOES
    TextBox textbox1 = new TextBox();
    textbox1.ID = "txt" + i.ToString(); //SET TEXT BOX NAME 
    textbox1.Attributes.Add("colVal", colName);  //SET NEW ATTRİBUTES TO TEXTBOX
    textbox1.Width = 500;


    form1.Controls.Add(textbox1);
}
praty
  • 535
  • 2
  • 9

2 Answers2

0

use Panel as this:

for (int i = 0; i < countStart; i++)    //Create all content of the table in here
{
    //CREATE ALL LABELS
    var p = new Panel();
    p.ID = "pnl" + ds1.Tables[0].Rows[i]["COLUMN_NAME"].ToString() + i.ToString();
    form1.Controls.Add(p);

    ...

    p.Controls.Add(lbl);

    ...

    p.Controls.Add(space);  //SPACE 

    ...


    p.Controls.Add(textbox1);
}
Jamshaid K.
  • 3,555
  • 1
  • 27
  • 42
Afshin Rashidi
  • 343
  • 2
  • 10
0

Suppose if a label exists in div, then find the label by its container like div.

<div id="divLbl" runat="server">
      <asp:Label runat="server" ID="lblToolsTechnology1" />
  </div>

 Label label = (Label)divLbl.FindControl("lblToolsTechnology1");
Abdul Khaliq
  • 2,139
  • 4
  • 27
  • 31