Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is the following code it is showing error again n again i can understand why it arises but the problem is that since i m new to C# can someone suggest me the code. i want the code that could solve my problem .please someone help me on this.
C#
public void box()
{        int i = 0;
            int k = Panel2.Controls.Count;
            DataSet ds1 = new DataSet();
            if (Session["ds"] != null)
            {
                ds1 = (DataSet)Session["ds"];
                if (Session["fill"] != null)
                {
                    i = Convert.ToInt32(Session["fill"].ToString());
                }
                for (int j = 0; j < i; j++)
                {
                    TableRow skillTable = new TableRow();
                    TableCell cell1 = new TableCell();
                    TableCell cell2 = new TableCell();
                    TableCell cell3 = new TableCell();
                    TableCell cell4 = new TableCell();
                    TableCell cell5 = new TableCell();
                    TableCell cell6 = new TableCell();
                    cell1.Text = ds1.Tables[0].Rows[j][0].ToString();
                    CheckBox ch1 = new CheckBox();                    
                    ch1.ID = "ch1" + j.ToString();
                    cell2.Controls.Add(ch1);
                    cell3.Text = "Year Of Exp";
                    TextBox txt1 = new TextBox();
                    txt1.ID = "txt1" + j.ToString();
                    cell4.Controls.Add(txt1);
                    cell5.Text = "Recently Used ";
                    TextBox txt2 = new TextBox();
                    txt2.ID = "txt2" + j.ToString();
                    cell6.Controls.Add(txt2);
                    skillTable.Cells.Add(cell1);
                    skillTable.Cells.Add(cell2);
                    skillTable.Cells.Add(cell3);
                    skillTable.Cells.Add(cell4);
                    skillTable.Cells.Add(cell5);
                    skillTable.Cells.Add(cell6);
                    Table1.Rows.Add(skillTable);
                }
            }
        }
Posted
Updated 6-Apr-16 19:53pm
v2
Comments
Pheonyx 4-Apr-13 6:56am    
Can you use the formatting built into this forum to make your code more readable please.
Use the Code tags, and indent where appropriate at the moment it is not simple to read!
CHill60 4-Apr-13 7:18am    
On which line is this error being displayed - use your debugger if you are not sure. Does it throw the error the first time this is run or only if it is run twice?
ZurdoDev 4-Apr-13 7:21am    
You need to create controls with unique ids. What are you stuck on?

You have two controls named ch10, but none is visible in you code-behind.

You could try doing a search in the aspx/aspx.cs for ch10 to find them and rename one. If the control is being added programatically then you'll need to find where it is being generated.

If neither of these things fixes the problem, you need to show the ASP.NET side of things as currently there isn't a control with ch10 available in the code-behind you have posted.
 
Share this answer
 
This error occurs when any control ID is missing or more than one control have the same ID assigned. to get rid of this error, make the ID values of each control unique.

see the example below, the loop increment value j is appended dynamically to the id value to make the id value increment

pnl.ID = "pnltype" + j.ToString();


C#
for (int j = 0; j < dtRtype.Rows.Count; j++)
{        
  pnl = new Panel();
  pnl.Width = panelWidth;
  pnl.Height = panelHeight;
  pnl.BackColor = Color.BlueViolet;
  pnl.BorderStyle = BorderStyle.Solid;
  pnl.BorderColor = System.Drawing.Color.White;
  pnl.BorderWidth = 2;
  pnl.Style["position"] = "absolute";
  pnl.Style["bottom"] = bottom.ToString() + "px";
  pnl.Style["left"] = left.ToString() + "px";
  pnl.ID = "pnltype" + j.ToString();

}
 
Share this answer
 
v2

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