This is a migrated thread and some comments may be shown as answers.

Capturing the free text into the ComboBox

1 Answer 236 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 14 Jul 2010, 06:21 PM
I want to type some data into the ComboBox Text area and hit enter to have that data added to the combobox.

How can I do that?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Jul 2010, 09:12 AM
Hello Ron,


Here s my complete code for achieving same functionality. I hope the code will work for you.

ASPX:
<telerik:RadComboBox ID="RadComboBox1" MarkFirstMatch="false" runat="server" AllowCustomText="True"
    AutoPostBack="True" OnClientKeyPressing="OnClientKeyPressing">
    <Items>
        <telerik:RadComboBoxItem Text="RadComboBoxItem1" />
        <telerik:RadComboBoxItem Text="RadComboBoxItem2" />
    </Items>
</telerik:RadComboBox>

CS:
protected void Page_Load(object sender, EventArgs e)
{
    if (RadComboBox1.Text != "")
    {     
        if (RadComboBox1.Items.FindItemByText(RadComboBox1.Text) == null)
        {
            RadComboBoxItem newItem = new RadComboBoxItem();
            newItem.Text = RadComboBox1.Text;
            RadComboBox1.Items.Add(newItem);
        }           
    }
}


JavaScript:
<script type="text/javascript">
    function OnClientKeyPressing(Sender, args) {
        if (args.get_domEvent().keyCode == 13) {
            __doPostBack('RadComboBox1.ClientID', '');
        }
    }
</script>


Good luck,
Shinu.
Tags
ComboBox
Asked by
Thomas
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or