[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

need drop down list containing checkboxes!

Deanna Delapasse

2/20/2004 3:36:00 AM

Hi,

Is it possible to create a dropdownlist containing checkbox items instead
of regular list items? I'm working on a project with VERY non-computer type
users and I need to allow multiple selection, but they'll never master
holding down the control key and clicking. Any help would be greatly
appreciated.

thanks,
Deanna


2 Answers

v-jetan

2/20/2004 9:15:00 AM

0


Hi Deanna,

Thank you for posting in the community!

Based on my understanding, you want to add checkbox into the dropdownlist
control to enable the customer to select more than one items.

===============================================
Actually, DropDownList will render as <select> html tag. While there is a
"multiple" property with <select> tag, which enable you to set whether
multiple items can be selected from a list. So you can just override the
DropDownList control add the "multiple" property like this:
this.Attributes.Add("multiple", "true");

Also, use Html server dropdownlist control may be more convenient.

If you still want to add checkbox into dropdownlist control, you can place
a checkboxlist control in a div tag, then use client javascript to show or
hide this div to simulate the Dropdownlist effect. In the sample code
below, I only add one empty item into the dropdownlist, but it does not
work well. Actually, you may make one little control whoes appearance is
the same as dropdownlist(You may use a picture in it), then do the same
logic.

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

The client javascript code:
<script language="javascript">
function showdiv()
{
debugger
document.all("WebCustomControl11_serverdiv").style.visibility="visible";
}

function hidediv()
{
debugger
document.all("WebCustomControl11_serverdiv").style.visibility="hidden";
}
</script>

Normally, you can dynamicly generate the client javascript code through
Page.RegisterClientScriptBlock with the Div.ClientID property.

====================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

v-jetan

2/24/2004 1:20:00 AM

0


Hi Deanna,

Does my reply make sense to you?

If you still have anything unclear, please feel free to tell me, I will
help you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.