MultiSelect Drop Down Box, in .Net

AID: 4144
  • Status: Published

1400 points

  • Bydinudany
  • TypeGeneral
  • Posted on2010-11-22 at 03:06:39
Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box?

As a normal case you can use a <div> to populate the checkbox items and, depending on the selected check boxes, you can add them to the selected array.  But in this case, dynamic population of the drop down is big problem.

Here my article describes creating a usercontrol in .Net, which can be used as a multiselect drop down box.

Create a control


The following example shows creating a web user control, adding one textbox, an imagebutton, and two checkboxes.
<div id="divMultiSelect">
    <table cellpadding="0" cellspacing="0" border="0" style=" border: 1px solid #7F9DB9;background-color: White ;">
        <tr >
            <td>
                <asp:TextBox ID="txtMultiSelect" runat="server" ReadOnly="True" Style="width: 150px;
                    font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #36478B; font-weight: normal" />
            </td>
            <td>
                <asp:ImageButton ID="imgMultiSelect" runat="server" Width="20px" OnClick="imgMultiSelect_Click"
                    ImageUrl="~/Images/MultiSelectDropDown.bmp" />
            </td>
        </tr>
    </table>
    <asp:CheckBoxList ID="cblSelectAll" runat="server" CellPadding="0" CellSpacing="0" BackColor="#F2F2F2" BorderColor="#7F9DB9" BorderWidth="1px"
        Width="163px" AutoPostBack="true" ToolTip="NotSelected" Style="border-bottom: 0px; vertical-align: top; height: 20px; clear: both;" RepeatLayout="Flow" 
		OnSelectedIndexChanged="cblSelectAll_SelectedIndexChanged">
    </asp:CheckBoxList>
    <br />
    <asp:CheckBoxList ID="cblMultiSelect" runat="server" BackColor="White" BorderColor="#7F9DB9" BorderWidth="1px" Width="163px" 
		Style="border-top: 0px; overflow: auto; overflow-y: scroll; margin-top: 8px; height: 200px;" RepeatLayout="Flow" AutoPostBack="true" 
		OnSelectedIndexChanged="cblMultiSelect_SelectedIndexChanged"
        OnDataBound="cblMultiSelect_DataBound">
        </asp:CheckBoxList>
</div>
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:

Select allOpen in new window



Server Side Control


Here is the code in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NRMA.NRMAServices;
using System.Collections;

/// <summary>
/// MultiSelect DropDown UserControl
/// </summary>
public partial class UserControl_MultiSelectDropDown : System.Web.UI.UserControl
{
    #region "Property Region"
    /// <summary>
    /// To get the selected values of a multi select drop down in a comma seperated string
    /// </summary>
    private string selectValues;
    /// <summary>
    /// To get the selected values of a multi select drop down in a comma seperated string
    /// </summary>
    public string SelectValues
    {
        get { return ViewState[this.ClientID] == null ? "0" : ViewState[this.ClientID].ToString(); }
        set
        {
            ViewState[this.ClientID] = value;
            selectValues = ViewState[this.ClientID].ToString();
        }
    }
    /// <summary>
    /// To get the selected values of a multi select drop down in a comma seperated string
    /// </summary>
    private string selectItems;
    /// <summary>
    /// To get the selected values of a multi select drop down in a comma seperated string
    /// </summary>
    public string SelectItems
    {
        get { return ViewState["name" + this.ClientID] == null ? "0" : ViewState["name" + this.ClientID].ToString(); }
        set
        {
            ViewState["name" + this.ClientID] = value;
            selectItems = ViewState["name" + this.ClientID].ToString();
        }
    }

    /// <summary>
    /// To get the multi select image button control
    /// </summary>
    private ImageButton imageMultiSelect;
    /// <summary>
    /// To get the multi select image button control
    /// </summary>
    public ImageButton ImageMultiSelect
    {
        get { return imgMultiSelect; }
        set { imageMultiSelect = value; }
    }

    /// <summary>
    /// To get the check box multi select control
    /// </summary>
    private CheckBoxList checkMultiSelect;
    /// <summary>
    /// To get the check box multi select control
    /// </summary>
    public CheckBoxList CheckMultiSelect
    {
        get { return cblMultiSelect; }
        set { checkMultiSelect = value; }
    }

    /// <summary>
    /// To get the check box select all control
    /// </summary>
    private CheckBoxList checkSelectAll;
    /// <summary>
    /// To get the check box select all control
    /// </summary>
    public CheckBoxList CheckSelectAll
    {
        get { return cblSelectAll; }
        set { checkSelectAll = value; }
    }
	
	/// <summary>
    /// Abstract class for classes with ID and Name 
    /// </summary>
    public  class IDNamePair
    {
        /// <summary>
        /// ID
        /// </summary>
        protected long iD;

        /// <summary>
        /// Name
        /// </summary>
        protected string name;

        /// <summary>
        /// ID
        /// </summary>
        public long ID
        {
            get { return iD; }
            set { iD = value; }
        }

        /// <summary>
        /// Name
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
    }
    #endregion

    #region "Events"
    /// <summary>
    /// Page load event of multi select drop down user control
    /// </summary>
    /// <param name="sender">sender object</param>
    /// <param name="e">event arguments</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        int _countOfSelectedItems = 0;
        if (!IsPostBack)
        {
            cblSelectAll.Visible = false;
            cblMultiSelect.Visible = false;
            cblSelectAll.Style.Add("position", "absolute");
            cblMultiSelect.Style.Add("position", "absolute");
        }
        if (cblSelectAll.Items.Count >= 1)
        {
            if (cblSelectAll.Items[0].Selected == true)
            {
                this.SelectValues = "0";
            }
        }
        else
        {
            for (int i = 0; i < cblMultiSelect.Items.Count; i++)
            {
                if (cblMultiSelect.Items[i].Selected == true)
                {
                    this.SelectValues = selectValues + cblMultiSelect.Items[i].Value.ToString() + ", ";
                    this.SelectItems = selectItems + cblMultiSelect.Items[i].Text.ToString() + ", ";
                    _countOfSelectedItems++;
                }

            }
            if (_countOfSelectedItems > 0)
            {
                this.SelectValues = selectValues.Substring(0, selectValues.Length - 2);
                this.SelectItems = selectItems.Substring(0, selectItems.Length - 2);
            }
        }
    }

    /// <summary>
    /// Onclick event of the Multi Select Image Button
    /// </summary>
    /// <param name="sender">sender object</param>
    /// <param name="e">image click event arguments</param>
    protected void imgMultiSelect_Click(object sender, ImageClickEventArgs e)
    {
        if (cblSelectAll.Visible == true && cblMultiSelect.Visible == true)
        {
            cblMultiSelect.Visible = false;
            cblSelectAll.Visible = false;
        }
        else
        {
            cblMultiSelect.Visible = true;
            cblSelectAll.Visible = true;
        }
    }

    /// <summary>
    /// Checkbox list multi select control selected index change event
    /// </summary>
    /// <param name="sender">sender object</param>
    /// <param name="e">event arguments</param>
    protected void cblMultiSelect_SelectedIndexChanged(object sender, EventArgs e)
    {
        int _countOfSelectedItems = 0;
        int _countOfUnSelectedItems = 0;
        cblSelectAll.Items[0].Selected = false;
        cblSelectAll.ToolTip = "NotSelected";
        for (int i = 0; i < cblMultiSelect.Items.Count; i++)
        {
            if (cblMultiSelect.Items[i].Selected == true)
            {
                this.selectValues = this.selectValues + cblMultiSelect.Items[i].Value.ToString() + ", ";
                this.SelectItems = this.selectItems + cblMultiSelect.Items[i].Text.ToString() + ", ";
                _countOfSelectedItems++;
            }
            else
            {
                _countOfUnSelectedItems++;
            }
        }
        if (_countOfSelectedItems == 1)
        {
            txtMultiSelect.Text = cblMultiSelect.SelectedItem.Text;
            this.SelectValues = cblMultiSelect.SelectedValue.ToString();
            this.SelectItems = cblMultiSelect.SelectedItem.ToString();

        }
        else if (_countOfSelectedItems > 1)
        {
            txtMultiSelect.Text = _countOfSelectedItems.ToString() + " Items Selected";
        }

        else
        {
            txtMultiSelect.Text = "";
            this.selectValues = "";
            this.SelectItems = "";
        }
        if (_countOfSelectedItems > 0 && _countOfSelectedItems != 1)
        {
            this.SelectValues = selectValues.Substring(0, selectValues.Length - 2);
            this.SelectItems = selectItems.Substring(0, selectItems.Length - 2);
        }
        if (_countOfUnSelectedItems == 0)
        {
            cblSelectAll.Items[0].Selected = true;
            cblSelectAll.ToolTip = "Selected";
            txtMultiSelect.Text = cblSelectAll.SelectedItem.Text;
            this.SelectValues = cblSelectAll.SelectedValue.ToString();
            this.SelectItems = cblSelectAll.SelectedItem.ToString();
        }
    }
    /// <summary>
    /// cblMultiSelect on data bound
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void cblMultiSelect_DataBound(object sender, EventArgs e)
    {
        int _index = 1;
        for (int i = 0; i <= cblMultiSelect.Items.Count - 1;i++ )
        {
            ListItem lst = cblMultiSelect.Items[i];
            if (_index % 2 == 0)
            {
                lst.Attributes.Remove("class");
                lst.Attributes.Add("class", "GraySpan");
            }
            else
            {
                lst.Attributes.Remove("class");
                lst.Attributes.Add("class", "WhiteSpan");
            }
            _index = _index + 1;
        }
    }
    /// <summary>
    /// Checkbox list select all control selected index change event
    /// </summary>
    /// <param name="sender">sender object</param>
    /// <param name="e">event arguments</param>
    protected void cblSelectAll_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (cblSelectAll.ToolTip == "NotSelected")
        {
            txtMultiSelect.Text = cblSelectAll.SelectedItem.Text;
            selectValues = cblSelectAll.SelectedValue.ToString();
            selectItems = cblSelectAll.SelectedItem.ToString();
            for (int i = 0; i < cblMultiSelect.Items.Count; i++)
            {
                cblMultiSelect.Items[i].Selected = true;
            }
            cblSelectAll.ToolTip = "Selected";
            if (cblSelectAll.Visible == true && cblMultiSelect.Visible == true)
            {
                cblMultiSelect.Visible = false;
                cblSelectAll.Visible = false;
            }
            else
            {
                cblMultiSelect.Visible = true;
                cblSelectAll.Visible = true;
            }
        }
        else if (cblSelectAll.ToolTip == "Selected")
        {
            txtMultiSelect.Text = "";
            selectValues = "";
            selectItems = "";
            for (int i = 0; i < cblMultiSelect.Items.Count; i++)
            {
                cblMultiSelect.Items[i].Selected = false;
            }
            cblSelectAll.ToolTip = "NotSelected";
        }
    }
    #endregion

    #region "Custom Methods"
    /// <summary>
    /// To Load the data into the Drop Down based on the super value
    /// </summary>
    /// <param name="_listInfo">ID Name Pair data that do be populated into the checkbox list</param>
    /// <param name="_allOptional">Boolean value to add all option in the dropdown</param>
    public void LoadDropDown(List<IDNamePair> _listInfo, bool _allOptional)
    {
        cblMultiSelect.Items.Clear();
        int _index = 1;
        for (int i = 0; i < _listInfo.Count; i++)
        {
            ListItem _thisListItem = new ListItem();
            if (_index % 2 == 0)
            {
                _thisListItem.Text = _listInfo[i].Name.ToString();
                _thisListItem.Value = _listInfo[i].ID.ToString();
                cblMultiSelect.Items.Add(_thisListItem);
            }
            else
            {
                _thisListItem.Text =_listInfo[i].Name.ToString() ;
                _thisListItem.Value = _listInfo[i].ID.ToString();
                cblMultiSelect.Items.Add(_thisListItem);
            }
            _index = _index + 1;
           
        }
        if (_allOptional)
        {
            if (cblMultiSelect.Items.Count != 1)
            {
                ListItem _thisListItem = new ListItem();
                _thisListItem.Text = "All";
                _thisListItem.Value = "0".ToString();
                cblSelectAll.Items.Clear();
                cblSelectAll.Items.Add(_thisListItem);
            }
            else
            {
                cblSelectAll.Enabled = false;
            }

            cblSelectAll.Items[0].Selected = true;
            cblSelectAll.ToolTip = "Selected";
            txtMultiSelect.Text = cblSelectAll.SelectedItem.Text;
            selectValues = cblSelectAll.SelectedValue.ToString();
            selectItems = cblSelectAll.SelectedItem.ToString();
            for (int i = 0; i < cblMultiSelect.Items.Count; i++)
            {
                cblMultiSelect.Items[i].Selected = true;
            }
        }
        else
        {
            int _countOfSelectedItems = 0;
            int _countOfUnSelectedItems = 0;
            if (cblMultiSelect.Items.Count != 1)
            {
                for (int i = 0; i < cblMultiSelect.Items.Count; i++)
                {
                    if (cblMultiSelect.Items[i].Selected == true)
                    {
                        _countOfSelectedItems++;
                    }
                    else
                    {
                        _countOfUnSelectedItems++;
                    }
                }
                if (_countOfSelectedItems == 1)
                {
                    txtMultiSelect.Text = cblMultiSelect.SelectedItem.Text;
                    selectValues = cblMultiSelect.SelectedValue.ToString();
                    selectItems = cblMultiSelect.SelectedItem.ToString();
                }
                else if (_countOfSelectedItems > 1)
                {
                    txtMultiSelect.Text = _countOfSelectedItems.ToString() + " Items Selected";
                }
                else
                {
                    txtMultiSelect.Text = "";
                    selectValues = "";
                    selectItems = "";
                }
                if (_countOfUnSelectedItems == 0)
                {
                    cblSelectAll.Items[0].Selected = true;
                    cblSelectAll.ToolTip = "Selected";
                    txtMultiSelect.Text = cblSelectAll.SelectedItem.Text;
                    selectValues = cblSelectAll.SelectedValue.ToString();
                    selectItems = cblSelectAll.SelectedItem.ToString();
                }
            }
            else
            {
                cblMultiSelect.Items[0].Selected = true;
                txtMultiSelect.Text = cblMultiSelect.SelectedItem.Text;
                selectValues = cblMultiSelect.SelectedValue.ToString();
                selectItems = cblMultiSelect.SelectedItem.ToString();
            }
        }
       
    }

	/// <summary>
    /// Overloaded method of LoadDropDown to populate the multiselect dropdown
    /// </summary>
    /// <param name="_listInfo"></param>
    /// <param name="_allOptional"></param>
    public void LoadDropDown(Hashtable _listInfo, bool _allOptional)
    {
        cblMultiSelect.Items.Clear();
        int _index = 0;
        foreach (DictionaryEntry de in _listInfo)
        {
            ListItem _thisListItem = new ListItem();
            if (_index % 2 == 0)
            {
                _thisListItem.Text = de.Value.ToString();
                _thisListItem.Value = de.Key.ToString();
                cblMultiSelect.Items.Add(_thisListItem);
            }
            else
            {
                _thisListItem.Text = de.Value.ToString() ;
                _thisListItem.Value = de.Key.ToString();
                cblMultiSelect.Items.Add(_thisListItem);
            }
            _index = _index + 1;
            
        }
        if (_allOptional)
        {
            if (cblMultiSelect.Items.Count != 1)
            {
                ListItem _thisListItem = new ListItem();
                _thisListItem.Text = "All";
                _thisListItem.Value = "0".ToString();
                cblSelectAll.Items.Clear();
                cblSelectAll.Items.Add(_thisListItem);
            }
            else
            {
                cblSelectAll.Enabled = false;
            }

            cblSelectAll.Items[0].Selected = true;
            cblSelectAll.ToolTip = "Selected";
            txtMultiSelect.Text = cblSelectAll.SelectedItem.Text;
            selectItems = cblSelectAll.SelectedItem.ToString();
            for (int i = 0; i < cblMultiSelect.Items.Count; i++)
            {
                cblMultiSelect.Items[i].Selected = true;
            }
        }
        else
        {
            int _countOfSelectedItems = 0;
            int _countOfUnSelectedItems = 0;
            if (cblMultiSelect.Items.Count != 1)
            {
                for (int i = 0; i < cblMultiSelect.Items.Count; i++)
                {
                    if (cblMultiSelect.Items[i].Selected == true)
                    {
                        _countOfSelectedItems++;
                    }
                    else
                    {
                        _countOfUnSelectedItems++;
                    }
                }
                if (_countOfSelectedItems == 1)
                {
                    txtMultiSelect.Text = cblMultiSelect.SelectedItem.Text;
                    selectValues = cblMultiSelect.SelectedValue.ToString();
                    selectItems = cblMultiSelect.SelectedItem.ToString();
                }
                else if (_countOfSelectedItems > 1)
                {
                    txtMultiSelect.Text = _countOfSelectedItems.ToString() + " Items Selected";
                }
                else
                {
                    txtMultiSelect.Text = "";
                    selectValues = "";
                    selectItems = "";
                }
                if (_countOfUnSelectedItems == 0)
                {
                    cblSelectAll.Items[0].Selected = true;
                    cblSelectAll.ToolTip = "Selected";
                    txtMultiSelect.Text = cblSelectAll.SelectedItem.Text;
                    selectValues = cblSelectAll.SelectedValue.ToString();
                    selectItems = cblSelectAll.SelectedItem.ToString();
                }
            }
            else
            {
                cblMultiSelect.Items[0].Selected = true;
                txtMultiSelect.Text = cblMultiSelect.SelectedItem.Text;
                selectValues = cblMultiSelect.SelectedValue.ToString();
                selectItems = cblMultiSelect.SelectedItem.ToString();
            }
        }
       
    }
    
    /// <summary>
    /// To Load the data into the Drop Down based on the seleced value
    /// </summary>
    /// <param name="_selectedIds">Array of selected items values</param>
    public void LoadDropDownValue(int[] _selectedIds)
    {
        if (_selectedIds[0] == 0)
        {
            cblSelectAll.Items[0].Selected = true;
            cblSelectAll.ToolTip = "Selected";
            txtMultiSelect.Text = cblSelectAll.SelectedItem.Text;
            selectValues = cblSelectAll.SelectedValue.ToString();
            selectItems = cblSelectAll.SelectedItem.ToString();
        }
        else
        {
            cblSelectAll.Items[0].Selected = false;
            cblSelectAll.ToolTip = "NotSelected";
            for (int i = 0; i < cblMultiSelect.Items.Count; i++)
            {
                cblMultiSelect.Items[i].Selected = false;
            }
            for (int i = 0; i < cblMultiSelect.Items.Count; i++)
            {
                for (int j = 0; j < _selectedIds.Length; j++)
                {
                    if (cblMultiSelect.Items[i].Value == _selectedIds[j].ToString())
                    {
                        cblMultiSelect.Items[i].Selected = true;
                    }
                }
            }
            if (_selectedIds.Length == 1)
            {
                txtMultiSelect.Text = cblMultiSelect.SelectedItem.Text;
                selectValues = cblMultiSelect.SelectedValue.ToString();
                selectItems = cblMultiSelect.SelectedItem.ToString();
            }
            else if (_selectedIds.Length > 1)
            {
                txtMultiSelect.Text = _selectedIds.Length.ToString() + " Items Selected";
            }
        }
    }
    
	/// <summary>
    /// To Load the data into the Drop Down based on the seleced value
    /// </summary>
    /// <param name="_selectedIds">Array of selected items values</param>
    
	public void LoadDropDownValue(string[] _selectedIds)
    {
        if (_selectedIds[0] == "0")
        {
            cblSelectAll.Items[0].Selected = true;
            cblSelectAll.ToolTip = "Selected";
            txtMultiSelect.Text = cblSelectAll.SelectedItem.Text;
            selectValues = cblSelectAll.SelectedValue.ToString();
            selectItems = cblSelectAll.SelectedItem.ToString();
        }
        else
        {
            cblSelectAll.Items[0].Selected = false;
            cblSelectAll.ToolTip = "NotSelected";
            for (int i = 0; i < cblMultiSelect.Items.Count; i++)
            {
                cblMultiSelect.Items[i].Selected = false;
            }
            for (int i = 0; i < cblMultiSelect.Items.Count; i++)
            {
                for (int j = 0; j < _selectedIds.Length; j++)
                {
                    if (cblMultiSelect.Items[i].Value == _selectedIds[j].ToString())
                    {
                        cblMultiSelect.Items[i].Selected = true;
                    }
                }
            }
            if (_selectedIds.Length == 1)
            {
                txtMultiSelect.Text = cblMultiSelect.SelectedItem.Text;
                selectValues = cblMultiSelect.SelectedValue.ToString();
                selectItems = cblMultiSelect.SelectedItem.ToString();
            }
            else if (_selectedIds.Length > 1)
            {
                txtMultiSelect.Text = _selectedIds.Length.ToString() + " Items Selected";
            }
        }
    }
    #endregion
}
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:

Select allOpen in new window



Explanation


Method LoadDropDown(), is used to fill the drop down with values.  This is an overloading method where you can pass either a list of IDNamePair entities or a Hash-table value to fill the multi-select drop down.

All the usable controls are populated into properties and exposed.  When you call this user control in a page, you can also easily access all these properties.

The SelectValues property of the multi-select drop down box control gives the selected values in a comma separated string. The SelectItems property returns the text values of the selected values.

There is a checkbox list of "select all," which is used to select all the options populated in the multi-select drop down.  And to unselect also.  There is an option to enable this in the multi-select drop down box, while binding the data to this control.
 
Asked On
2010-11-22 at 03:06:39ID4144
Tags

.net

Topic

.NET

Views
847

Comments

Expert Comment

by: saswt_ds on 2012-04-19 at 04:07:21ID: 50702

Excellent post. It is really helpful. Multiple selection of values from a dropdownlist is clearly defined here. Coding is very neat and clear for understanding.

Expert Comment

by: saswt_ds on 2012-04-19 at 04:07:23ID: 50703

Excellent post. It is really helpful. Multiple selection of values from a dropdownlist is clearly defined here. Coding is very neat and clear for understanding.

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top .NET Programming Experts

  1. CodeCruiser

    588,856

    Sage

    6,000 points yesterday

    Profile
    Rank: Genius
  2. kaufmed

    377,702

    Wizard

    10 points yesterday

    Profile
    Rank: Genius
  3. BuggyCoder

    268,007

    Guru

    1,600 points yesterday

    Profile
    Rank: Sage
  4. TheLearnedOne

    232,552

    Guru

    4,900 points yesterday

    Profile
    Rank: Savant
  5. Idle_Mind

    193,005

    Guru

    0 points yesterday

    Profile
    Rank: Savant
  6. JamesBurger

    156,812

    Guru

    2,000 points yesterday

    Profile
    Rank: Sage
  7. wdosanjos

    124,308

    Master

    2,000 points yesterday

    Profile
    Rank: Genius
  8. Dhaest

    115,720

    Master

    0 points yesterday

    Profile
    Rank: Genius
  9. sedgwick

    112,918

    Master

    1,600 points yesterday

    Profile
    Rank: Genius
  10. nepaluz

    101,325

    Master

    0 points yesterday

    Profile
    Rank: Sage
  11. MlandaT

    95,921

    Master

    2,100 points yesterday

    Profile
    Rank: Genius
  12. navneethegde

    74,442

    Master

    0 points yesterday

    Profile
    Rank: Wizard
  13. Masteraco

    70,367

    Master

    0 points yesterday

    Profile
    Rank: Wizard
  14. binaryevo

    70,365

    Master

    0 points yesterday

    Profile
    Rank: Guru
  15. ambience

    69,104

    Master

    0 points yesterday

    Profile
    Rank: Sage
  16. emoreau

    68,230

    Master

    0 points yesterday

    Profile
    Rank: Genius
  17. PaulHews

    49,486

    0 points yesterday

    Profile
    Rank: Genius
  18. AndyAinscow

    45,290

    0 points yesterday

    Profile
    Rank: Genius
  19. Chinmay_Patel

    43,411

    0 points yesterday

    Profile
    Rank: Genius
  20. ged325

    41,700

    2,600 points yesterday

    Profile
    Rank: Genius
  21. RolandDeschain

    41,317

    0 points yesterday

    Profile
    Rank: Sage
  22. nishantcomp2512

    39,486

    0 points yesterday

    Profile
    Rank: Wizard
  23. tommyBoy

    36,550

    0 points yesterday

    Profile
    Rank: Genius
  24. mroonal

    35,000

    0 points yesterday

    Profile
    Rank: Sage
  25. santhimurthyd

    34,650

    0 points yesterday

    Profile
    Rank: Wizard

Hall Of Fame