Radcombobox Value not updating on postback

4 posts, 0 answers
  1. Carlos Franken
    Carlos Franken avatar
    4 posts
    Member since:
    Apr 2010

    Posted 09 Jun 2011 Link to this post

    I have experienced lots of problems with the RadCombobox control with trying to bind it while having Enableloadondemand set to true
    I'm currently binding on my gridview OnDataBound event by creating a single item and inserting it at index 0.

    Now when i need to change te selected Item the enableloadondemand fires correctly and loads items filtered on the text typed in the text area.

    after selecting an item the OnSelectedIndexchanged event fires and the radcombobox text is updated to the text of the selected item.
    however the Value never gets updated and I will have to perform another query to my recordset to select the value.

    Since the text gets updated normally when selecting a different item how come the value doesn't ?
    i have a snippet with how i handle the selectedindexchanged event.

    protected void RCB1_Selectedindexchanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        RadComboBox rcb = (RadComboBox)sender; // combobox that fires event
        string hi = rcb.SelectedValue; // combobox value, always old value
        string ha = rcb.Text; // combobox text, always text from newly selected item
        string hu = e.OldValue; // working correctly always value of previously selected item
        string ho = e.OldText; //working correctly always text of previously selected item
        string he = e.Value; // not working as one would expect it to work, always OLD value
        string hy = e.Text; // working as expected always NEW text
        string hiy = rcb.SelectedItem.Value; // Always old value
        string hyi = rcb.SelectedItem.Text; // always old value
        DataView dv = (DataView)SqlDataSource2.Select(new DataSourceSelectArguments());
        string huu; // correct value after looping through intire datasource, would like to avoid this 
        foreach (DataRowView row in dv)
            if (row["Naambedrtot"].ToString() == rcb.Text)
                huu = row["klantnummer"].ToString();
        if (e.OldValue != e.Value) // always the same so selected value never gets changed
            rcb.SelectedValue = e.Value;

    Is this the correct behavior ?

    I would think that if you can send the correct new text , the new value should be simple too.
  2. Kalina
    Kalina avatar
    918 posts

    Posted 13 Jun 2011 Link to this post

    Hello Carlos Franken,

    I am not sure that I fully understand the scenario that you are trying to implement.
    As I can see at the code snippet pasted here - you are trying to access the RadComboBox SelectedItem at server-side.
    However RadComboBox items are not accessible at server-side if they have been populated via Load On Demand - please find more details about this topic here.

    Let me suggest you take a look at this Code Library article. In the sample project published there you can find a working example with RadComboBox(with Load On Demand enabled) and GridView.

    Kind regards,
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. Carlos Franken
    Carlos Franken avatar
    4 posts
    Member since:
    Apr 2010

    Posted 14 Jun 2011 Link to this post

    Thanks for the response,  i'll try to further clarify my issue.

    It is very simple, i know that when using Automatic-loadonDemand there is no itemcollection to acces in code.
    When i change my selection clientside why is the text property updated to the newly selected item, but not the value.

    In other words,

    if i have 3 items (created by a datasource, not in markup) and load on demand enabled, the value stored in my database is 1.

    item1.text = text1  -  item1.value  = 1
    item2.text = text2  -  item2.value  = 2
    item3.text = text3  -  item3.value  = 3

    by getting the value from my database in a datasource, and getting the accosiated text for this value from a database table
    i create a new radcombobox item with value = 1 and text = text1.
    This is then inserted at index 0 of the combobox control.

    this all works as expected, the problem starts when i select a different item.

    When i press the textarea or the down arrow on the control and now select "text3"
    this updates the text property of my radcombobox but not the value

    so when i now acces the control in code, the text property is "text3".
    However the SelectedValue property is still 1 , while i need it to be 3.

    hope this clarifies my problem a bit and you are able to provide a clear answer to why this is the way it is.

  4. Carlos Franken
    Carlos Franken avatar
    4 posts
    Member since:
    Apr 2010

    Posted 14 Jun 2011 Link to this post

    I have figuered it out,

    By creating a RadComboBoxItem server-side and inserting it at index 0.
    (A method used to get the control to work within EditItemTemplates when using Load-On-Demand)
    the RadComboBox NEVER updates it's SelectedValue (reason unknown to me).

    Workaround, Do not use the suggested Item creation and insertion at index 0,
    instead just set the Controls Text and SelectedValue properties in code.

    After this the SelectedValue was updated correctlly when choosing a different Item.
Back to Top