Click here to Skip to main content
15,914,416 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
C#
Table table = new Table();
table.ID = "Table1";
Page.Form.Controls.Add(table);



Hear Creting 10 lables id is generating 0,1,2....10. i need how to change the 0 to Name1, 2 to name2 ....
Posted
Updated 18-Jul-12 5:26am
v3

//Hear Creting 10 lables id is generating 0,1,2....10. i need how to change the 0 to Name1, 2 to name2 ....
Place this there:
C#
lbl.ID = "Name"+ (i+1).ToString();
 
Share this answer
 
v3
Hi,

Where you want to change the Name
C#
Lable lb=[table].FindControl(ControlID);
lb.ID= [ Change To your Custom ID]
</pre>
 
Share this answer
 
Comments
Sandeep Mewara 17-Jul-12 4:42am    
Why to FindControl? It's being created at runtime, then and there!
Suvabrata Roy 17-Jul-12 4:43am    
then just set it their

you mentioned that you need to change Name of lable
Hello use this code .........

Table table = new Table();
        table.ID = "Table1";
        Page.Form.Controls.Add(table);

        for (int i = 0; i < 10; i++) // Loop for Row
        {
            TableRow row = new TableRow();
            for (int j = 0; j < 1; j++) // Loop for Column
            {
                TableCell cell = new TableCell();

                Label lbl = new Label();
                lbl.ID = "Name"+(i+1); // This is first method id like--> Name1,Name2 etc.  
   // lbl.ID = "Name"+(i+1)+ "_" + j.ToString(); // This is Second method id like--> Name1_0,Name2_1 etc.
                lbl.Text = i.ToString();
                cell.Controls.Add(lbl);

                //Hear Creting 10 lables id is generating 0,1,2....10. i need how to change the 0 to Name1, 2 to name2 ....

                TextBox tb = new TextBox();
tb.ID = "txtBox1" + i.ToString();
                //tb.ID = "Name" + (i+1); // U can use for text box Id
                RequiredFieldValidator reqfldVal = new RequiredFieldValidator();
                reqfldVal.ID = "RequiredValidator" + i;
                reqfldVal.ControlToValidate = "txtBox1" + i;
                reqfldVal.ErrorMessage = "Not Empty";
                reqfldVal.SetFocusOnError = true;
                cell.Controls.Add(tb);
                row.Cells.Add(cell);
            }

            table.Rows.Add(row);
        }
 
Share this answer
 
v5
Comments
2011999 17-Jul-12 5:19am    
first method not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900