In this article, I will show you how to create a multi-select control in ASP.NET. I will keep this article short and sweet so you can just use the code
in your applications. Previously I referred to many codes for a multiselect dropdown but I found they were all a little complex to implement. So I decided to try it on my own.
Let's see how I implemented this.
First, you must install AJAX controls in Visual Studio. I am using VS2010. This is because I am using the popup control extender to implement this control.
Using the code
Place a textbox in Design view and assign the popup extender for that textbox. An important thing to note here is you must place your textbox control within the
Afterwards, you create a panel and within this panel, you put a checkboxlist. You then assign this panel to the
PopupControlID property of the popup extender.
Now take a look at this code:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="multidropdown.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit" TagPrefix="asp" %>
Here, you select the datasource from your SQL Server database.
Finally, we need to do one more modification in the code-behind. Each time we click the checkboxlist, the selected value will be added to the textbox control.
So in the selected index changed event, you will place this code:
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
string name = "";
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
name += CheckBoxList1.Items[i].Text + ",";
TextBox1.Text = name;