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

GridDropDownColumn binding by code

1 Answer 275 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ali
Top achievements
Rank 1
Ali asked on 16 Dec 2008, 07:52 PM
I am binding the GridDropDownColumn (GDDC) in the ItemDataBound Event and it is working perfect. The problem is that when the grid is in display mode ony (NOT in EDIT nor in INSERT) I cannot see any values in this column. The reason is ofcourse that I am binding the GDDC in edit mode only as specified in the code below. Please see that I am not using DataSourceID in the GDDC markup. I need to bind it through code.

Any help would be appreciated.

Ali
protected void RadGrid1_ItemDataBound(Object source, GridItemEventArgs e)  
        {  
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
            {  
                //first reference the edited grid item   
                GridEditableItem editedItem = e.Item as GridEditableItem;  
                GridEditManager editMan = editedItem.EditManager;  
 
                //reference the column editor which holds the dropdown list instance in the edit form  
                GridDropDownColumnEditor editor = editMan.GetColumnEditor("SectionID"as GridDropDownColumnEditor;  
 
 
                string selectedValue = editor.SelectedValue;  
                // change the data source for ContactTitle with custom code here  
 
                editor.DataSource = mySectionController.getAllModuleSections();  
                editor.DataBind();  
                editor.SelectedValue = selectedValue;  
            }  
 
        } 
<telerik:GridDropDownColumn DataField="SectionID" HeaderText="SectionID" 
UniqueName="SectionID" ListTextField="SectionName" ListValueField="SectionID">  
</telerik:GridDropDownColumn> 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Dec 2008, 05:33 AM
Hi Ali,

You can try binding the Literal present in the GridDropDownColumn as shown in the code below, to bind the dropdowncolumn in normal mode of the grid.
aspx:
<telerik:GridDropDownColumn UniqueName="DropDownColumn" >         
        </telerik:GridDropDownColumn> 

cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem && !e.Item.IsInEditMode)  
        {  
            GridDataItem item = (GridDataItem)e.Item; 
            Literal litrl = (Literal)item["DropDownColumn"].Controls[0];             
            litrl.Text = DataBinder.Eval(item.DataItem, "ProductName").ToString(); 
        }  
   }  

Thanks
Princy.
Tags
Grid
Asked by
Ali
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or