articles

Home / DeveloperSection / Articles / Ajax Toolkit ComboBox Control in ASP.Net

Ajax Toolkit ComboBox Control in ASP.Net

Pushpendra Singh27098 06-Dec-2010

The ComboBox works like a combination between a standard ASP.NET DropDownList control and a TextBox control. You can either select from a pre-existing list of items or enter a new item.

The ComboBox control is initialized with a set of items.

ComboBox Properties:

·         DropDownStyle - Determines whether the user is allowed to enter text that does not match an item in the list, and whether the list is always displayed. If "DropDownList" is specified, users are not allowed to enter text that does not match an item in the list. When "DropDown" (the default value) is specified, any text is allowed. If "Simple" is specified, any text is allowed and the list is always displayed regardless of the AutoCompleteMode property value.

·         AutoCompleteMode - Determines how the ComboBox automatically completes the text that is typed into it. When "Suggest" is specified, the ComboBox will show the list, highlight the first matched item. If "Append" is specified, the ComboBox will append the remainder of the first matched item to the user-typed text and highlight the appended text. When "SuggestAppend" is specified, both of the above behaviors are applied. If "None" (the default value) is specified, the ComboBox's auto-complete behaviors are disabled. See in this fig.

 

Ajax Toolkit ComboBox Control in ASP.Net

Code:

<%-- ScriptManager control manages client script for AJAX enabled ASP.NET pages--%>

Write these code on default.aspx page

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
 
<cc1:ComboBox ID="ComboBox1" runat="server" AutoCompleteMode="Suggest" AutoPostBack="True" DropDownStyle="Simple">
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>Lanka</asp:ListItem>
<asp:ListItem>Pak</asp:ListItem>
<asp:ListItem>Aus</asp:ListItem>
<asp:ListItem>Aps</asp:ListItem>
</cc1:ComboBox>
 
<%--Here  AutoCompleteMode="Suggest" which specified that ComboBox will show the list, highlight the first matched item.--%>
 
<asp:Button ID="Button1" runat="server" Text="select country" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server"></asp:Label>

Write these code on button1 click event

protected void Button1_Click(object sender, EventArgs e)
    {       
         Label1.Text = "You selected" + ComboBox1.SelectedItem.Text;      
    }

Run the project

When you enter any text in ComboBox then it will highlight matching value

Ajax Toolkit ComboBox Control in ASP.Net

When you click select country button then selected value will display in the Label

Ajax Toolkit ComboBox Control in ASP.Net


Updated 07-Sep-2019

Leave Comment

Comments

Liked By