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

Dynamically change default text for comboxbox in EditForm

1 Answer 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Iris
Top achievements
Rank 1
Iris asked on 03 Aug 2012, 09:15 AM
I have a radgrid that displays product information. One of the product information is Product Group. In EditForm, I have a RadComboBox that will enable the user to change the Product Group for the product. The RadComboBox will lists all available Product Groups (sorted in ascending).

For example:
I have a product Z that is currently a member of Product Group B. There are 3 Product Groups available, namely A, B and C. Currently, when I open the EditForm for product Z, the item that is displayed as the default product group on the RadComboBox is Product Group A. I want the combobox to display the default product group based on the product's current product group, in this case Product Group B.

I tried to follow this guide (http://www.telerik.com/help/aspnet-ajax/combobox-insert-default-item-when-databinding.html), but when the RadComboBox DataBound event is fired, I don't have the information on which product calls for it, hence I cannot make it display the correct product group name.

Currently I put the code for inside RadGrid ItemDataBound event. I get the default product group to be displayed accordingly but it creates a duplicate and I don't think this is the correct way to do this.

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        GridEditFormItem item = e.Item as GridEditFormItem;
         RadComboBox statusComboBox = (RadComboBox)item.FindControl("RadComboBox1");
 
        // get the parent GridDataItem for this form
        // (i.e. which row this edit form is generated for)
        GridDataItem parentGridItem;
        parentGridItem = item.ParentItem;
 
        // put the current product group on combobox's first entry
        statusComboBox.Items.Insert(0, new RadComboBoxItem(parentGridItem["product_group"].Text, string.Empty));
    }
}

Please help.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Iris
Top achievements
Rank 1
answered on 06 Aug 2012, 06:18 AM
Nevermind, I've found the way to do it.

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 
  // EditMode's settings
  if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
  {
    GridEditFormItem item = e.Item as GridEditFormItem;
 
    // get the parent GridDataItem for this form
    // (i.e. which row this edit form is generated for)
    GridDataItem parentGridItem;
    parentGridItem = item.ParentItem;
    RadComboBoxItem comboBoxItem;
 
    RadComboBox comboBoxProductGroup = (RadComboBox)item.FindControl("RadComboBox1");
    comboBoxItem = comboBoxProductGroup.FindItemByText(parentGridItem["product_group"].Text);
    comboBoxItem.Selected = true;
  }
}
Tags
Grid
Asked by
Iris
Top achievements
Rank 1
Answers by
Iris
Top achievements
Rank 1
Share this question
or