Multiple Select Telerik RadComboBox in Code Behind

Telerik have a great demo for a combobox that has checkboxes to enable multiple selection.

http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/templates/defaultcs.aspx

Great! Except again, how do you do this in code behind?

First, check out my post about defining multiple columns in a RadComboCox:

http://andrewwhitten.wordpress.com/2010/04/11/telerik-multi-column-radcombobox-from-code-inside-a-composite-control/

Just add a checkbox into the row with your other items. You just change the InstantiateIn method to:

        /// <summary>
        /// Create the template
        /// </summary>
        /// <param name="container"></param>
        public void InstantiateIn(System.Web.UI.Control container)
        {
            PlaceHolder ph = new PlaceHolder();
            CheckBox checkBox = new CheckBox();
            Label item1 = new Label();
            Label item2 = new Label();
            Label item3 = new Label();

            checkBox.ID = "checkBox";
            item1.ID = "item1";
            item2.ID = "item2";
            item3.ID = "item3";

            switch (templateType)
            {
                case ListItemType.Header:
                    ph.Controls.Add(new LiteralControl("<ul><li class='colCheckBox'>Select</li><li class='col1'>Code</li><li class='col2'>Description</li><li class='col3'>Type</li></ul>"));
                    break;
                case ListItemType.Item:
                    ph.Controls.Add(new LiteralControl("<ul><li class='colCheckBox'>"));
                    ph.Controls.Add(checkBox);
                    ph.Controls.Add(new LiteralControl("</li><li class='col1'>"));
                    ph.Controls.Add(item1);
                    ph.Controls.Add(new LiteralControl("</li><li class='col2'>"));
                    ph.Controls.Add(item2);
                    ph.Controls.Add(new LiteralControl("</li><li class='col3'>"));
                    ph.Controls.Add(item3);
                    ph.Controls.Add(new LiteralControl("</li></ul>"));
                    ph.DataBinding += new EventHandler(Item_DataBinding);
                    break;
            }
            container.Controls.Add(ph);
        }
About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: