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

RadGrid with GridDropDownColumn when expanding row

3 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex Vr
Top achievements
Rank 1
Alex Vr asked on 29 Aug 2010, 09:02 PM
Hello Everyone,
First of all thanking for the great support from the Telerik team.

I have a problem with RadGrid when I'm using it with GridDropDownColumn.

My scenario:

I have a grid with GridDropDownColumn column. I load the values of  the ComboBox during ItemDataBound event and and select the values from it if I'm in edit mode. In this situation I don't see the text of this column in the grid table.
So I added in the ItemDataBound event a check if the item is GridDataItem and then set the GridDataItem.Text  to the right value (The text should be a little bit different from the text used in the ComboBox). It works OK now and showing the text in the Grid table.
Now I face another problem, I have NestedTemplate in this grid. When I expand the column the text of the GridDropDownColumn column disapears... How can I resolve this problem?

My code:
protected void AttributesRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            GridEditManager editMan = editedItem.EditManager;
  
            GridDropDownListColumnEditor fieldTypeEditor = editMan.GetColumnEditor("FieldType") as GridDropDownListColumnEditor;
            GridDropDownListColumnEditor attributeCategoryIDEditor = editMan.GetColumnEditor("AttributeCategoryID") as GridDropDownListColumnEditor;
              
            fieldTypeEditor.ComboBoxControl.Items.Add(new RadComboBoxItem("Text", "0"));
            fieldTypeEditor.ComboBoxControl.Items.Add(new RadComboBoxItem("Yes/No", "1"));
            fieldTypeEditor.ComboBoxControl.Items.Add(new RadComboBoxItem("Multi Yes/No", "2"));
            fieldTypeEditor.ComboBoxControl.Items.Add(new RadComboBoxItem("Select", "3"));
  
            FillAttributeCategoriesComboBox(attributeCategoryIDEditor.ComboBoxControl);
  
            if (e.Item.RowIndex != -1)
            {
                CellphonesCL.Database.attributes attr = (CellphonesCL.Database.attributes)e.Item.DataItem;
  
                fieldTypeEditor.ComboBoxControl.SelectedValue = attr.FieldType.ToString();
                attributeCategoryIDEditor.ComboBoxControl.SelectedValue = attr.AttributeCategoryID.ToString();
            }
        }
        else if (e.Item is GridDataItem)
        {
            GridDataItem dataItem = e.Item as GridDataItem;
            CellphonesCL.Database.attributes attr = (CellphonesCL.Database.attributes)e.Item.DataItem;
  
            dataItem["AttributeCategoryID"].Text = attr.attributecategories.Title;
            dataItem["FieldType"].Text = attributes.GetAttributeFieldTypeStr((AttributeFieldType)attr.FieldType);
        }
    }


Regards,
Alex.

3 Answers, 1 is accepted

Sort by
0
Alex Vr
Top achievements
Rank 1
answered on 31 Aug 2010, 08:56 PM
Anyone?
0
Radoslav
Telerik team
answered on 02 Sep 2010, 08:33 AM
Hi Alex,

When you set the Text property of the dataItem["FieldType"] cell into GridItemDataBound event handler you replace the default rendered Literal control into the dataItem["FieldType"].Controls collection. Then when you expand the nested item the Literal control is rendered again on GridItemCreated event and the value in Text property is lost. To achieve the desired functionality you need to set the value to the (dataItem["FieldType"].Controls[0] as Literal).Text property:
else if (e.Item is GridDataItem)
{
   GridDataItem dataItem = e.Item as GridDataItem;
   CellphonesCL.Database.attributes attr = (CellphonesCL.Database.attributes)e.Item.DataItem;
  
   (dataItem["AttributeCategoryID"].Controls[0] as Literal).Text = attr.attributecategories.Title;
   (dataItem["FieldType"].Controls[0] as Literal).Text = attributes.GetAttributeFieldTypeStr((AttributeFieldType)attr.FieldType);
}

Please give it try and let me know if the issue still persists.

Kind regards,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alex Vr
Top achievements
Rank 1
answered on 02 Sep 2010, 09:22 AM
Hi Radoslav,

Thanks, it works OK now.

Best Regards,
Alex
Tags
Grid
Asked by
Alex Vr
Top achievements
Rank 1
Answers by
Alex Vr
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or