找到具有相同ID“ch10”的多个控件。 FindControl要求控件具有唯一ID。 [R

问题描述:

这里是以下代码它再次显示错误n我可以理解为什么它出现但问题是因为我是C#的新手可以有人建议我代码。我想要的代码可以解决我的问题。请有人帮我解决这个问题。

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.

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);
                }
            }
        }

你有两个名为ch10的控件,但没有一个是可见的在你的代码隐藏。



您可以尝试在aspx / aspx.cs中搜索ch10来查找它们并重命名。如果以编程方式添加控件,那么您将需要找到它的生成位置。



如果这些都没有解决问题,则需要显示ASP.NET方面的事情目前在你发布的代码隐藏中没有ch10可用的控件。
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.


当缺少任何控件ID或多个控件ID时会发生此错误控件具有相同的ID。为了摆脱这个错误,使每个控件的ID值唯一。



参见下面的例子,循环增量值j动态附加到id值到使id值增加



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





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();


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();

}