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

RADCombobox inside a RADGRID

2 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Navneet
Top achievements
Rank 1
Navneet asked on 27 Jun 2011, 09:30 PM
Hi,

I am having difficulty setting the default value for the combox inside a grid. Getting an error

Selection out of range
Parameter name: value

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Selection out of range
Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: Selection out of range
Parameter name: value]
   Telerik.Web.UI.RadComboBox.PerformDataBinding(IEnumerable dataSource) +173
   Telerik.Web.UI.RadComboBox.OnDataSourceViewSelectCallback(IEnumerable data) +471
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback


My Goal is to show combobox as a templated column inside a grid. I am using the   SelectedValue='<%# Bind("ReqUpdate") %>'  to do the binding. The grid is bounded with the datasource using "RadGrid1_NeedDataSource".  When I had set the combox Text property, I was not getting any error but the first item in the combo was getting selected.

Other note: When I replace the radcombox with the DropDownList, everything works fine and the value is set properly. But I need to handle client side, onselectedindexchange event. As a result I need to use RADCOMBOX.

Please let me know how can I quickly resolve this issue.

Thanks,
navneet

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 Jun 2011, 05:52 AM
Hello Navaneet,

I am not quite sure how you are populating the RadCombobox. If you populate RadComboBox with data using ASP.NET 2.0 or 3.5 DataSource types, you can simply set the SelectedValue :
  •     SelectedValue='<%#Bind("CompanyName") %>' 
When you use Load On Demand or Automatic Load On Demand - you can add the previously selected Item by in the RadGrid OnItemDataBound event when in Edit Mode.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
      if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
       {
           GridEditFormItem editItem = (GridEditFormItem)e.Item;
           RadComboBox combo = (RadComboBox)editItem.FindControl("RadCombo1");
           combo.DataSource = "";// create sql query and populate combo in edit form based on the value in variable 'value'
           combo.DataTextField = "";
           combo.DataValueField = "";
           combo.DataBind();
       }
   }

Check out the following documentation for more on this.
RadComboBox in RadGrid.

Thanks,
Princy.
0
Navneet
Top achievements
Rank 1
answered on 28 Jun 2011, 02:14 PM
Princy:

Thanks for the response. My combobox has only two values. yes and no.

Got it resolved by putting the value for the list item. I had just set the text and not the value property of the RadComboBoxItem. That works for ASP Dropdown list but not for RadComboBox. But not a biggie... Just getting a feel of the telerik controls. I love them.

  <telerik:RadComboBoxItem runat="server" Text="Yes"
Value="Yes"
/>
 <telerik:RadComboBoxItem runat="server" Text="No" value="No" />

Thanks once again
Navneet                             
Tags
Grid
Asked by
Navneet
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Navneet
Top achievements
Rank 1
Share this question
or