Click here to Skip to main content
15,886,835 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
C#
foreach (string item in valueslist)
                        {
                            TableRow tr = new TableRow();
                            TableCell tc = new TableCell();
                            TableCell col2 = new TableCell();

                            Label lb = new Label();
                            lb.Text = item;

                            TextBox tb1 = new TextBox();
                            tb1.Style["text-align"] = "Right";
                            
                            tb1.ID = "txt" + k;
                            tb1.Text = "0";

                            tb1.EnableViewState = true;
                            tb1.AutoPostBack = true;
                            tb1.TextChanged += new EventHandler(tb1_TextChanged);

                            int cnt = 0;
                            tb1.ID = "Tab" + cnt.ToString();//Not incremented tabindex
                            tb1.TabIndex = (short)(cnt);
                            cnt++; 
                            

                            tb1.Text = "0";
                            string ids = string.Format("lb{0}", k);
                            lb.ID = ids;
                            tc.Controls.Add(lb);
                            col2.Controls.Add(tb1);

                            tr.Controls.Add(tc);
                            tr.Controls.Add(col2);

                            table.Controls.Add(tr);

                            k++;

                        }
Posted
Updated 9-Aug-12 1:54am
v2
Comments
[no name] 9-Aug-12 7:54am    
Should we expect a question to arrive any time?
Christian Amado 9-Aug-12 8:04am    
So, What is the question here? Nice code (?)
Sebastian T Xavier 9-Aug-12 8:15am    
Just a code dump...
Christian Amado 9-Aug-12 8:26am    
May be he didn't explain better (?)
Sebastian T Xavier 9-Aug-12 8:29am    
He need to...

1 solution

C#
int cnt = 0;
foreach (string item in valueslist)
                        {
                            TableRow tr = new TableRow();
                            TableCell tc = new TableCell();
                            TableCell col2 = new TableCell();
 
                            Label lb = new Label();
                            lb.Text = item;
 
                            TextBox tb1 = new TextBox();
                            tb1.Style["text-align"] = "Right";
                            
                            tb1.ID = "txt" + k;
                            tb1.Text = "0";
 
                            tb1.EnableViewState = true;
                            tb1.AutoPostBack = true;
                            tb1.TextChanged += new EventHandler(tb1_TextChanged);
 
                            tb1.ID = "Tab" + cnt.ToString();//Not incremented tabindex
                            tb1.TabIndex = (short)(cnt);
                            cnt++; 
                            
 
                            tb1.Text = "0";
                            string ids = string.Format("lb{0}", k);
                            lb.ID = ids;
                            tc.Controls.Add(lb);
                            col2.Controls.Add(tb1);
 
                            tr.Controls.Add(tc);
                            tr.Controls.Add(col2);
 
                            table.Controls.Add(tr);
 
                            k++;
 
                        }


The problem is your cnt variable. Always be 0.

Hope it helps
 
Share this answer
 
v2
Comments
AmitGajjar 9-Aug-12 8:12am    
Correct 5+ , if he set cnt to zero how could he expect other value :D
Christian Amado 9-Aug-12 8:27am    
May be he needs some algorithmics classes =)
Christian Amado 9-Aug-12 11:17am    
Mark as solution if helps to you @2011999

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