Example E1331
Visible to All Users

Combo Box for ASP.NET Web Forms - How to format input text for multi-column combo box

In multi-column mode, the edit box displays the selected row’s values separated by a semicolon. Use the TextFormatString property to format the selected item’s output text. The text pattern can contain literals and indexed placeholders such as {0}, {1}, and so on.

Implementation Details

In this example, a radio button list control allows users to select a pattern to apply to the combo box text. The ASPxRadioButtonList.SelectedIndexChanged event handler sets the ASPxComboBox.TextFormatString property according to the selected pattern.

C#
protected void ASPxRadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { if (ASPxRadioButtonList1.SelectedIndex == 0) { ASPxComboBox1.TextFormatString = "{0} {1}, {2} Company"; } if (ASPxRadioButtonList1.SelectedIndex == 1) { ASPxComboBox1.TextFormatString = "{1} {0}, {2} Company"; } }

Files to Review

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" %> <%@ Register assembly="DevExpress.Web.v13.1, Version=13.1.14.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web" tagprefix="dxcb" %> <!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:ASPxRadioButtonList ID="ASPxRadioButtonList1" runat="server" ClientInstanceName="rbl" OnSelectedIndexChanged="ASPxRadioButtonList1_SelectedIndexChanged" > <ClientSideEvents SelectedIndexChanged="function(s, e) { e.processOnServer=true; }" /> <Items> <dxe:ListEditItem Text="FirstName LastName, Company" Value="Format1" /> <dxe:ListEditItem Text="LastName FirstName, Company" Value="Format2" /> </Items> </dxe:ASPxRadioButtonList> <br /> <dxe:ASPxComboBox ID="ASPxComboBox1" runat="server" DataSourceID="AccessDataSource1" IncrementalFilteringMode="Contains" TextFormatString="{0} {1}, {2} Company" ValueType="System.String" Width="450px"> <Columns> <dxe:ListBoxColumn Caption="First Name" FieldName="FirstName" Name="FirstName" /> <dxe:ListBoxColumn Caption="Last Name" FieldName="LastName" Name="LastName" /> <dxe:ListBoxColumn Caption="Company" FieldName="Company" Name="Company" /> </Columns> </dxe:ASPxComboBox> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Contacts.mdb" SelectCommand="SELECT [FirstName], [LastName], [Company] FROM [Customers]"> </asp:AccessDataSource> </div> </form> </body> </html>
WebSite/Default.aspx.cs(vb)
C#
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void ASPxRadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { if (ASPxRadioButtonList1.SelectedIndex == 0) { ASPxComboBox1.TextFormatString = "{0} {1}, {2} Company"; } if (ASPxRadioButtonList1.SelectedIndex == 1) { ASPxComboBox1.TextFormatString = "{1} {0}, {2} Company"; } } }

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.