473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DropDownList with CheckBoxes

Hi,

For the page I'm developing I need a DropDownList with CheckBoxes on it, so that the users can choose more than one option without having to use the Ctrl key (and it's more intuitive). Because my options are being retrieved from the Database, the list of option can be really big, so using a CheckBoxList would use a lot of space.
Please, can anyone help me with this? I'm almost desperate! I have been search for a couples day, but having problems in everything I tried.
What I'm trying to do now is override the DropDownList control (as suggested in this forum: http://www.dotnet247.com/247referenc...42/211693.aspx), but I'm havng problems right in the frist line:

Public Class CheckBoxDropDownList : System.Web.UI.WebControls.WebControl, INamingContainer

System is highlighted and asking me for a declaration ("Declaration expected"). What is wrong then? I created this class in the folder App_Code. Is it correct? Please, I need some help with this.

I'm using ASP.NET 3.5, Visual Studio 2008 and VB.NET. And the DropDownList is inside a GridView.

Thanks in advance,

Ana
Aug 12 '09 #1
2 10774
The problem above was because I was using C# syntax. I correct the syntax and the DDL is working. But the thing is: the ChckBoxes are not in the DDL and I don't know ho to get the selectedValues (if more than one). Can anyone help me?
My code now is like this:

Expand|Select|Wrap|Line Numbers
  1. Public Class CheckBoxDropDownList
  2.     Inherits System.Web.UI.WebControls.WebControl
  3.     Implements INamingContainer
  4.  
  5.     Protected Overrides Sub CreateChildControls()
  6.         MyBase.CreateChildControls()
  7.         Dim ddl As DropDownList = New DropDownList()
  8.         Dim li As ListItem = New ListItem("")
  9.  
  10.         ddl.Items.Add(li)
  11.         ddl.Width = New Unit(100)
  12.         ddl.Attributes.Add("multiple", "true")
  13.         ddl.Attributes.Add("onmousedown", "showdiv()")
  14.         ddl.Attributes.Add("onclick", "showdiv()")
  15.         ddl.Attributes.Add("ondragover", "hidediv()")
  16.         ddl.Attributes.Add("onmouseout", "hidediv()")
  17.  
  18.         Dim cbl As CheckBoxList = New CheckBoxList()
  19.         cbl.Width = New Unit(80)
  20.  
  21.         Dim li1 As ListItem = New ListItem("ListItem1")
  22.         Dim li2 As ListItem = New ListItem("ListItem2")
  23.         Dim li3 As ListItem = New ListItem("ListItem3")
  24.  
  25.         cbl.Items.Add(li1)
  26.         cbl.Items.Add(li2)
  27.         cbl.Items.Add(li3)
  28.  
  29.         Dim div As System.Web.UI.HtmlControls.HtmlGenericControl = New System.Web.UI.HtmlControls.HtmlGenericControl("div")
  30.  
  31.         div.ID = "serverdiv"
  32.         div.Controls.Add(cbl)
  33.         div.Style.Add("BORDER-RIGHT", "black 1px solid")
  34.         div.Style.Add("BORDER-TOP", "black 1px solid")
  35.         div.Style.Add("BORDER-LEFT", "black 1px solid")
  36.         div.Style.Add("BORDER-BOTTOM", "black 1px solid")
  37.         div.Style.Add("VISIBILITY", "hidden")
  38.  
  39.         Me.Controls.Add(ddl)
  40.         Me.Controls.Add(div)
  41.     End Sub
  42. End Class
Aug 12 '09 #2
Frinavale
9,735 Expert Mod 8TB
You can use CSS to add a vertical scroll bar to the ChecKBoxList.

Place the CheckBoxList in a Panel or a <div>. Set the style for this Panel/<div> so that it is the height that you want it to be and also set the style to have overflow:scroll (this will make the scroll bar visible).

You could also look into using the AjaxToolkit's DropDown control.
Aug 14 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: DJ Dev | last post by:
Hi All, I have a complex problem. I have dropdownlists (usually 3-5) and the user selects some value from these and for each value selected, datagrids are shown to the user. I am creating the...
1
by: Steve Caliendo | last post by:
Hi, I'm having trouble with multiple dynamically generated dropdownlists. On my web page I have several text boxes / labels / checkboxes and dropdownlists I have no problem setting the other...
3
by: PontiMax | last post by:
Hi, I'm searching for a drop-down list control whose items are check boxes. That list control should make it possible to select multiple items at once... Any idea? Many thanks in advance,...
3
by: RFS666 | last post by:
Hello together, I tried to find out about populating an asp.net server control (a dropdownlist) from the clientside jscript, but I didn't find a solution up to now. I cannot use a html...
3
by: ton | last post by:
How can I detect that the user has modified the data on the page where several textboxes, checkboxes and dropdownlist exist. Ton
4
by: Sevu | last post by:
I am working with ASP.NET.I am using ReportViwer Control to show my report.I like to add dropdownlist with in the reportviewer control. ( Not top to the control some thing like that).I need to...
2
by: Phil Sandler | last post by:
I am trying to do something which seems (to me) to be very simple, and yet I can't seem to figure it out. I have a gridview and a formview. When a user clicks "select" in the gridview, the...
0
by: =?Utf-8?B?Tkg=?= | last post by:
Is it possible to use multiple checkboxes in a dropdownlist?
6
by: thanigaimani83 | last post by:
Hi guys. i can explain for my doubt with example.see.my table have multiple type of employee details like as Mangemment,Programmer,Designers,Accountants,ContractEmployees.Each type of department...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.