This ascx user control, the
MultiCheckCombo, allows the user to select more than one option inside a
DropDownList. The different items that are being checked are being copied in the box area of the control.
The great thing of this control is that it doesn't close the check panel until you click outside the control. Example: you can check more than one item at once.
In ASP.NET C#, if you need a web control that allows the user to check more than one option in a
DropDownList, you can use this user control freely.
Well, first of all, this control was made in Microsoft Visual Studio 2008, with .NET 3.5 (2.0) and was written in C#. To use it, you need to have properly installed the
AjaxControlToolkit in your project.
Using the Code
Again: You need to have installed the AjaxControlToolkit in your project.
This control is fairly easy to implement. Simply copy the 3 ascx files into your project.
Then replace the namespace in both ascx and ascx.cs files with
E.g.: Let's suppose your project's name is
TestMultiCheck, replace in the ascx file the
Control tag with the name of your namespace/project:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MultiCheckCombo.ascx.cs"
And in your ascx.cs file, change the namespace to:
Well, then drag and drop the main file (MultiCheckCombo.ascx) to your Page Designer.
You may drag the control inside or outside an
UpdatePanel, but you need a ScriptManager at the beginning of the body tag of your aspx page.
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
When you drag the control, the following line should be added automatically to the beginning of your aspx page:
<%@ Register src="MultiCheckCombo.ascx" tagname="MultiCheckCombo" tagprefix="uc1" %>
And the code of the control looks like this (it also will be added automatically):
<uc1:MultiCheckCombo ID="MultiCheckCombo1" runat="server" />
Then, in the code behind (C#), you have to fill the values of the control.
You can fill it with an
ArrayList or with an
A: Easy mode: Filling the
MultiCheckCombo with an
ArrayList array = new ArrayList();
for (int i=0;i<100;i++) array.Add(i.ToString());
B: Other option is to fill the
MultiCheckCombo with an
OdbcConnection con =
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = con;
cmd.CommandText = "select text,id from ...........";
OdbcDataReader dr = cmd.ExecuteReader();
MultiCheckCombo1.AddItems(dr, "text", "id");
And that's it. You can now test it.
Some important properties of this controls are:
MultiCheckCombo1.WidthCheckListBox = 200;
MultiCheckCombo1.Width = 250;
MultiCheckCombo1.Enabled = true;
MultiCheckCombo1.fontSizeCheckBoxList = FontUnit.Small;
MultiCheckCombo1.fontSizeTextBox = FontUnit.XSmall;
Some important methods of this control are:
Points of Interest
I hope you can make it work. Cheers! ENJOY IT!
By the way, my e-mail is email@example.com.