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

GridBoundColumn to GridDropDownColumn

3 Answers 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Duncan Evans
Top achievements
Rank 1
Duncan Evans asked on 25 Jan 2010, 12:30 AM
I have a RadGrid with AutoGenerated GridBoundColumns.

This works great, however i am trying to make one of these columns a GridDropDownColumn from the ColumnCreated() event. I can't find any examples of this anywhere. This post: http://www.telerik.com/help/aspnet/grid/grdcustomizeconfiguregriddropdowncolumn.html is not helping me very much being that all my columns are GridBoundColumns, i have no GridDropDownColumns and (GridDropDownListColumnEditor)(editMan.GetColumnEditor()) fails every time.

Can someone tell me how to set a GridBoundColumn as a GridDropDownColumn?

Thanks,

Duncan

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 25 Jan 2010, 11:25 AM
Hi,

You can add a dynamically created  DropDownlist in the ItemCreated event of the grid,  to the Controls  collections of the required column in th edit mode as shown below:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
          if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditableItem editForm = (GridEditableItem)e.Item; 
            editForm["ColumnUniqueName"].Controls[0].Visible = false
            DropDownList list=new DropDownList(); 
            list.ID = "DropDownList1"
            list.Items.Add("Item1"); 
            list.Items.Add("Item1"); 
            list.Items.Add("Item1"); 
            editForm["ColumnUniqueName"].Controls.Add(list); 
        }   
         
    } 


Thanks,
Princy




0
Duncan Evans
Top achievements
Rank 1
answered on 25 Jan 2010, 08:11 PM
Great that seems to work, but how to si set the SelectedValue to the value of the row being edited?
0
Princy
Top achievements
Rank 1
answered on 27 Jan 2010, 09:30 AM
Hello Duncan,

You can check out the following example to achieve the required:
c#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
    {  
          if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))  
        {  
            GridEditableItem editForm = (GridEditableItem)e.Item;  
            editForm["ColumnUniqueName"].Controls[0].Visible = false;  
            DropDownList list=new DropDownList();  
            list.ID = "DropDownList1";              
            editForm["ColumnUniqueName"].Controls.Add(list);  
            list.DataSourceID = "SqlDataSource1"
            list.DataTextField = "ProductName"
            list.DataValueField = "ProductName";               
            list.DataBind(); 
        }             
    }  
 
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditableItem editForm = (GridEditableItem)e.Item;            
            ((DropDownList)editForm["ColumnUniqueName"].FindControl("DropDownList1")).SelectedValue = DataBinder.Eval(editForm.DataItem, "ProductName").ToString(); 
 
        }   
   } 

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