Example E1332
Visible to All Users

Combo Box for ASP.NET Web Forms - How to add items to an editor on the client in multi-column mode

This example demonstrates how to create a multi-column combo box editor and populate it with items on the client.

Overview

Create a combo box editor and populate it with columns.

ASPx
<dx:ASPxComboBox ID="ASPxComboBox1" runat="server" ClientInstanceName="comboBox" ValueType="System.String" Width="350px" TextFormatString="{0} {1}"> <Columns> <dx:ListBoxColumn Caption="First Name" Name="First Name" ToolTip="First Name" /> <dx:ListBoxColumn Caption="Last Name" Name="Last Name" ToolTip="Last Name" /> </Columns> </dx:ASPxComboBox>

Add a text editor and a button to the page. In the button's client-side Click event handler, call the combo box editor's AddItems method to add an item to the editor's item collection based on the text editor's value. To remove all items from the collection, call the editor's ClearItems method.

ASPx
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" ClientInstanceName="firstName" Width="170px" /> <dx:ASPxTextBox ID="ASPxTextBox2" runat="server" ClientInstanceName="lastName" Width="170px" /> <dx:ASPxButton ID="ASPxButton2" runat="server" Text="Add " AutoPostBack="False"> <ClientSideEvents Click="function(s, e) { var fName=firstName.GetValue(); var lName=lastName.GetValue(); firstName.SetText(''); lastName.SetText(''); var FullName = new Array(fName,lName); comboBox.AddItem(FullName); }" /> </dx:ASPxButton> <dx:ASPxButton ID="ASPxButton1" runat="server" Text="Clear Items" AutoPostBack="False"> <ClientSideEvents Click="function(s, e) { comboBox.ClearItems(); }" /> </dx:ASPxButton>

Files to Review

Documentation

Example Code

WebSite/Default.aspx
ASPx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register assembly="DevExpress.Web.v13.1, Version=13.1.14.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web" tagprefix="dxe" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <dxe:ASPxLabel ID="ASPxLabel1" runat="server" Text="First Name"> </dxe:ASPxLabel> <dxe:ASPxTextBox ID="ASPxTextBox1" runat="server" ClientInstanceName="firstName" Width="170px"> </dxe:ASPxTextBox> <br /> <dxe:ASPxLabel ID="ASPxLabel2" runat="server" Text="Last Name"> </dxe:ASPxLabel> <dxe:ASPxTextBox ID="ASPxTextBox2" runat="server" ClientInstanceName="lastName" Width="170px"> </dxe:ASPxTextBox> <br /> <dxe:ASPxButton ID="ASPxButton2" runat="server" Text="Add " AutoPostBack="False"> <ClientSideEvents Click="function(s, e) { var fName=firstName.GetValue(); var lName=lastName.GetValue(); firstName.SetText(''); lastName.SetText(''); var FullName = new Array(fName,lName); comboBox.AddItem(FullName); }" /> </dxe:ASPxButton> <br /> <dxe:ASPxComboBox ID="ASPxComboBox1" runat="server" ClientInstanceName="comboBox" ValueType="System.String" Width="350px" TextFormatString="{0} {1}"> <Columns> <dxe:ListBoxColumn Caption="First Name" Name="First Name" ToolTip="First Name" /> <dxe:ListBoxColumn Caption="Last Name" Name="Last Name" ToolTip="Last Name" /> </Columns> </dxe:ASPxComboBox> <br /> <dxe:ASPxButton ID="ASPxButton1" runat="server" Text="Clear Items" AutoPostBack="False"> <ClientSideEvents Click="function(s, e) { comboBox.ClearItems(); }" /> </dxe:ASPxButton> </div> </form> </body> </html>

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.