selected value do not set on multicolumn combobox

4 posts, 0 answers
  1. atif iqbal
    atif iqbal avatar
    7 posts
    Member since:
    Feb 2010

    Posted 05 Mar 2010 Link to this post

    I make a multi column combo box. if we type in that combobox then only matched values will return. So far so good but when i want to select some specific element on button click event by setting selectedvalue property then it does not show that value in the combo box. my html and c# code is given below:

    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <telerik:RadComboBox ID="RadComboBox1" runat="server" Skin="Vista" Height="190px"  
            Width="420px" MarkFirstMatch="true" EnableLoadOnDemand="true"
            HighlightTemplatedItems="true" OnClientItemsRequested="UpdateItemCountField"
            OnDataBound="RadComboBox1_DataBound" OnItemDataBound="RadComboBox1_ItemDataBound"
            ontextchanged="RadComboBox1_TextChanged" OnClientKeyPressing="HandkeKeyPress" >
                    <li class="col1">Name</li>
                    <li class="col2">Number</li>
                    <%--<li class="col3">Title</li>--%>
                    <li class="col1">
                        <%# DataBinder.Eval(Container.DataItem, "Name") %></li>
                    <li class="col2">
                        <%# DataBinder.Eval(Container.DataItem, "Number") %></li>
                    <%--<li class="col3">
                        <%# DataBinder.Eval(Container.DataItem, "ContactTitle") %></li>--%>
                A total of
                <asp:Literal runat="server" ID="RadComboItemsCount" />

    and c# code is:

     private DataTable table;
        protected void Page_Load(object sender, EventArgs e)

        public void DoDataBind()
            DataTable dt = CreateData();       
            RadComboBox1.DataSource = dt.DefaultView;

        protected void RadComboBox1_DataBound(object sender, EventArgs e)
            ((Literal)RadComboBox1.Footer.FindControl("RadComboItemsCount")).Text = Convert.ToString(RadComboBox1.Items.Count);
        private DataTable CreateData()
            table = new DataTable();
            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Number", typeof(int));
            table.Rows.Add(new object[] { "one", "1" });
            table.Rows.Add(new object[] { "two", "2" });
            table.Rows.Add(new object[] { "three", "3" });
            table.Rows.Add(new object[] { "four", "4" });
            table.Rows.Add(new object[] { "five", "5" });
            table.Rows.Add(new object[] { "six", "6" });
            return table;
        protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)

            DataTable dt = new DataTable();
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Number", typeof(int));
            DataRow[] foundRows;
            foundRows = table.Select("Name LIKE '" + e.Text + "%'");
            foreach (DataRow dr in foundRows)

            RadComboBox1.DataSource = dt;

        protected void RadComboBox1_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
            e.Item.Text = ((DataRowView)e.Item.DataItem)["Name"].ToString() + " (" +((DataRowView)e.Item.DataItem)["Number"].ToString() +")";
            e.Item.Value = ((DataRowView)e.Item.DataItem)["Number"].ToString();
        protected void RadComboBox1_TextChanged(object sender, EventArgs e)
        protected void Button1_Click(object sender, EventArgs e)
            RadComboBox1.SelectedValue = 2.ToString();
  2. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 05 Mar 2010 Link to this post

    Maybe you should enclose your DoDataBind() function in an if(!Page.IsPostBack) statement to prevent the value that was set in the button click from being lost during a postback. I'm guessing that's the reason it's not showing.

    Tell me if that works.
  3. DevCraft R3 2016 release webinar banner
  4. atif iqbal
    atif iqbal avatar
    7 posts
    Member since:
    Feb 2010

    Posted 08 Mar 2010 Link to this post

    No, this is not the reason. I found it myself just also set the text of combo box in the button click event as given below:

    RadComboBox1.SelectedValue = 2.ToString();

    RadComboBox1.Text = RadComboBox1.SelectedItem.Text;

  5. Simon
    Simon avatar
    2281 posts

    Posted 09 Mar 2010 Link to this post

    Hello atif iqbal,

    Load On Demand Items are not persisted across postbacks. So when you type something in the RadComboBox and load new Items on postback they will not be available. What is more in your case, you are binding the RadComboBox on each page load, so on postback it will have other Items loaded in it in the Button Click event handler.

    Please provide more details about your requirement so that we provide you with a more specific answer.

    All the best,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top