views:

1985

answers:

1

I have what I think should be a straightforward question. I have a RadGrid with FormTemplate editing and AJAX enabled. One of the fields in the FormTemplate is a RadComboBox filled with U.S. State selections. I can bind the RadComboBox to the data source to populate all the items, but I'm not able to set the SelectedValue attribute.

This RadComboBox is loaded when the Edit button is clicked for a row on the RadGrid. A custom FormTemplate is used and the contents of the row being edited are loaded via AJAX.

A: 

If you are DataBinding, its literally as easy as adding

SelectedValue='<%# Bind("FieldName")%>'

Inside the FormTemplate declaration of the RadComboBox.

If you however want to programmatically determine what value to select, then you need to implement ItemDataBound in the RadGrid, like the following example:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
        { 
            GridEditFormItem editFormItem = (GridEditFormItem)e.Item; 
            RadComboBox combo = (RadComboBox)editFormItem.FindControl("yourControlName"); 
            combo.SelectedValue= Somevalue;
        } 
    } 
Serapth
It should be, but Visual Studio acts like the SelectedValue attribute doesn't exist for this control. Including it anyway throws the following exception: Message: Sys.WebForms.PageRequestManagerServerErrorException: Selection out of range Parameter name: value
Kyle Noland
Here is my control:<telerik:RadComboBox ID="RadComboBox1" DataSourceID="SqlDataSource1" DataTextField="company_name" DataValueField="company_id" Width="300" Skin="Office2007" SelectedValue="<%# Bind('company_name') %>" runat="server" />
Kyle Noland
You may have a problem with your Telerik install. If you pull your RadComboBox out of the Grid so its on its own, does everything work? If you can, edit your first post to include the entire markup of the RadGrid, especially the FormTemplate section.
Serapth
One possible cause of that problem is if the SelectedValue doesn't match up with the available Values.
Serapth
Pulling the RadComboBox out of the Grid still does not let me set a SelectedValue. I am using Visual Studio 2010 and the Q1 2010 RadControl for ASP.NET AJAX.
Kyle Noland
At this point, without more code to look at, I don't think I can help you. I am using Rad Controls with VS2k10 aswell, but I havent upgraded from Q3 2009 yet, but I doubt that is the issue. By the way, if the ComboBox is inside a DataBound grid and shares the same Datasource, don't specify DataSourceID.
Serapth