RadComboBox displaying incorrect value

5 posts, 0 answers
  1. Eric
    Eric avatar
    2 posts
    Member since:
    Jan 2012

    Posted 08 Aug 2011 Link to this post

    Using ASP.Net 4.0;

    Hello,
    I am working in the edit form of a RadGrid, and I have built a RadComboBox with 5 values set in its datasource in its PreRender function, with a selected value preselected when the user opens the edit form. Everything is working fine: the selected value is being loaded into the control, and when the user saves the form, the correct value is saved to database.

    However, when the form is first opened, the displayed text is of the first value in the box: not the selected value. For example, the item at index 3 is marked as selected and is saved when the form save is fired, however when the form is opened the text of the item at index 0 is displayed.

    Anyone have experience with an issue like this? Thanks!

    Eric
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 09 Aug 2011 Link to this post

    Hello Eric,

    Please check below code.

    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem edititem = (GridEditableItem)e.Item;
                RadComboBox RadComboBox1 = (RadComboBox)edititem.FindControl("RadComboBox1");
                dynamic data = new[] {
                    new { ID = 1, Name ="Name1"},
                    new { ID = 2, Name = "Name2"},
                    new { ID = 3, Name = "Name3"},
                    new { ID = 4, Name = "Name4"},
                    new { ID = 5, Name = "Name5"},
                    new { ID = 6, Name ="Name6"},
                    new { ID = 7, Name = "Name7"},
                    new { ID = 8, Name = "Name8"},
                    new { ID = 9, Name = "Name9"},
                    new { ID = 10, Name = "Name10"},
                    new { ID = 11, Name ="Name11"},
                    new { ID = 12, Name = "Name12"},
                    new { ID = 13, Name = "Name13"},
                    new { ID = 14, Name = "Name14"},
                    new { ID = 15, Name = "Name15"}
                };
                RadComboBox1.DataSource = data;
                RadComboBox1.DataTextField = "Name";
                RadComboBox1.DataValueField = "ID";
                RadComboBox1.DataBind();
     
                Label lblName = edititem.FindControl("lblName") as Label; // csv value of selected values of RadcomboBox
     
                //lblName.Text = ",1,2,"
     
                string strTemp = string.Empty,strComma =  string.Empty;
                if (!string.IsNullOrEmpty(lblName.Text))
                {
                    foreach(RadComboBoxItem item in RadComboBox1.Items)
                    {
                        if(lblName.Text.Contains(","+item.Value+","))
                        {
                            strTemp += strComma + strTemp;
                            strComma = ",";
                        }
                    }
                }
     
                RadComboBox1.Text = strTemp; // you selected value's text here.
            }
        }

    let me know if any concern.

    Thanks,
    Jayesh Goyani
  3. Eric
    Eric avatar
    2 posts
    Member since:
    Jan 2012

    Posted 09 Aug 2011 Link to this post

    Jayesh,
    While this is a helpful and effective workaround, I'm afraid there might be an underlying issue that may pop up again and (horror of horrors) wreak havoc when I push this to a server. Any ideas what might be causing this?

    Thanks!
    Eric
  4. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 09 Aug 2011 Link to this post

    Hello,

    There is not any issue in code.

    Note : when we checked the checkbox at that time checked item text add to to the combobox Text with help of Javascript.
    But when we checked the item from codebehind at that time Javascript function was not Call/fired so we can only see only checked item but not their text in Combobox.

    Let me know if any concern.

    Thanks,
    Jayesh Goyani
  5. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 12 Aug 2011 Link to this post

    Hi Eric,

    Could you clarify which version of the controls you are using and also please try to provide the implementation of your PreRender event handler function. Even though the PreRender event is not the appropriate one to populate the RadComboBox I've made a couple of tests and the control was working as expected.

    Greetings,
    Dimitar Terziev
    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.

Back to Top