本文介绍了如何复选框添加到asp.net下拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I am doing databinding to a dropdown and I want to allow multiple selection using a check box in side the drop down. How can I do that. thanks
解决方案
public class CheckBoxDropDownList :
System.Web.UI.WebControls.WebControl,INamingContainer
{
protected override void CreateChildControls()
{
base.CreateChildControls ();
DropDownList ddl=new DropDownList();
ListItem li=new ListItem("");
ddl.Items.Add(li);
ddl.Width =new Unit(100);
ddl.Attributes.Add("onmousedown", "showdiv()");
ddl.Attributes.Add("onclick", "showdiv()");
ddl.Attributes.Add("ondragover", "hidediv()");
ddl.Attributes.Add("onmouseout", "hidediv()");
CheckBoxList cbl=new CheckBoxList();
cbl.Width=new Unit(80);
ListItem li1=new ListItem("ListItem1");
ListItem li2=new ListItem("ListItem2");
ListItem li3=new ListItem("ListItem3");
cbl.Items.Add(li1);
cbl.Items.Add(li2);
cbl.Items.Add(li3);
System.Web.UI.HtmlControls.HtmlGenericControl div=new
System.Web.UI.HtmlControls.HtmlGenericControl("div");
div.ID="serverdiv";
div.Controls.Add(cbl);
div.Style.Add("BORDER-RIGHT", "black 1px solid");
div.Style.Add("BORDER-TOP", "black 1px solid");
div.Style.Add("BORDER-LEFT", "black 1px solid");
div.Style.Add("BORDER-BOTTOM", "black 1px solid");
div.Style.Add("VISIBILITY", "hidden");
this.Controls.Add(ddl);
this.Controls.Add(div);
}
}
这篇关于如何复选框添加到asp.net下拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!