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

RadComboBox displaying incorrect value

4 Answers 112 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 08 Aug 2011, 11:35 PM
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

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 09 Aug 2011, 09:40 AM
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
0
Eric
Top achievements
Rank 1
answered on 09 Aug 2011, 03:38 PM
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
0
Jayesh Goyani
Top achievements
Rank 2
answered on 09 Aug 2011, 05:50 PM
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
0
Dimitar Terziev
Telerik team
answered on 12 Aug 2011, 11:30 AM
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.

Tags
ComboBox
Asked by
Eric
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Eric
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or