C#ASP.NET Wrap通过动态添加的Label Control动态添加了CheckBox Control

时间:2017-12-13 22:41:51

标签: c# asp.net dynamic controls label

我希望复选框包含在标签中,这样如果他们点击Label,就会检查CheckBox。一旦将鼠标悬停在Label上,我还需要使用descArea进行显示。这些也必须是动态的,并在后面的代码中创建。到目前为止,我有两种方法,都有自己的问题......

此选项不允许调用JS函数让descArea向下滑动

caPanel.Controls.Add(new LiteralControl(
                "<div class='col-md-6'>"+
                    "<div id='AButton" + t.Rows[i]["ID"].ToString() + "' class='caLabel' onmouseenter='slideDescriptionDown(this.id);' onmouseleave='slideDescriptionDown(this.id);' >" +
                        "<label>"));

                            CheckBox aCheckBox = new CheckBox();
                            aCheckBox.ID = "checkbox" + t.Rows[i]["ID"].ToString();
                            caPanel.Controls.Add(aCheckBox);

                ca.Controls.Add(new LiteralControl("&nbsp;&nbsp;" + t.Rows[i]["NAME"].ToString() + 
                        "</label>"+
                    "</div>"+
                    "<div class='alert alert-info aDescription' id='descArea" + t.Rows[i]["ID"].ToString() + "'>" +
                        "<span id='desc" + t.Rows[i]["CA_ID"].ToString() + "'>" + t.Rows[i]["Description"].ToString() + "</span>" +
                    "</div>"+
                "</div>"));

此单词不允许在点击CheckBox时检查Label。我检查了代码,Label显示为span

         caPanel.Controls.Add(new LiteralControl("<div class='row caSectionRow'>" +
                "<div class='col-md-6'>"));

                    Label aName = new Label();
                    aName.ID = "AButton" + t.Rows[i]["ID"].ToString();
                    aName.Attributes.Add("class", "caLabel");
                    aName.Attributes.Add("onmouseenter", "slideDescriptionDown(this.id);");
                    aName.Attributes.Add("onmouseleave", "slideDescriptionDown(this.id);");
                    aName.Text = "&nbsp;&nbsp;" + t.Rows[i]["NAME"].ToString();

                    CheckBox aCheckBox = new CheckBox();
                    aCheckBox.ID = "checkbox" + t.Rows[i]["ID"].ToString();

                caPanel.Controls.Add(aCheckBox);
                caPanel.Controls.Add(aName);

                caPanel.Controls.Add(new LiteralControl(
                    "<div class='alert alert-info aDescription' id='descArea" + t.Rows[i]["ID"].ToString() + "'>" +
                        "<span id='desc" + t.Rows[i]["ID"].ToString() + "'>" + t.Rows[i]["Description"].ToString() + "</span>" +
                    "</div>" +
                "</div>"));

1 个答案:

答案 0 :(得分:0)

我在尝试显示我提议的第一个选项的descArea时发现JS函数本身存在错误。对于descArea,我没有ID正确。它附加了MainContent_aContent_以实现所有控件在ASP.NET中必须具有的UniqueID属性。

When is the ctl00 prefix added?

https://msdn.microsoft.com/en-us/library/1d04y8ss(v=vs.100).ASPX