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

Check RadComboBox for value

2 Answers 566 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 26 Apr 2013, 07:19 PM
How and where can you check a RadComboBox for a value? I am getting an error because I am trying to set the selected value of my RCB to a value in my grid that I use databinder to get at. If the value is not in the original dataset I bound to my RCB it errors out. What I want to do is when I open my custom edit form that has this RCB in it, check to see if the value from the grid exists in the available items of the RCB. I cannot add it as it is no longer a valid option but my client keeps it for historical records. I am calling the following code in the pageLoad method but it is not working as it seems as if the RCB data items are not available here.

    myDDL.DataTextField = ds.Tables[0].Columns["DATA"].ToString();
    myDDL.DataValueField = ds.Tables[0].Columns[0].ToString();
    myDDL.DataSource = ds.Tables[0];
 
    var myValue = String.Empty;
    var ddlValue = DataBinder.Eval(DataItem, "DATA");
    Session["ddlValue"] = ddlValue;
    myValue = Session["ddlValue"].ToString();
    
    if (DataItem != null)
    {
        if (myDDL.FindItemByValue(ddlValue.ToString()) == null)
        {
            myDDL.SelectedIndex = -1;
        }
        else
        {
            myDDL.SelectedValue = ddlValue.ToString();
        }
    }
    else
    {
        myDDL.SelectedValue = myValue;
    }
}

2 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 30 Apr 2013, 12:50 PM
Yikes no one knows this?
0
Accepted
Plamen
Telerik team
answered on 01 May 2013, 01:47 PM
Hello John,

 
If you want to use the DataItem we recommend using the ItemDataBound serve event and set the desired property of the item according to your scenario.

Hope this will be helpful. 

Greetings,
Plamen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ComboBox
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or