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

Populate dropdown in edit mode

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
anu
Top achievements
Rank 1
anu asked on 01 Nov 2008, 11:33 AM
Hi,
I have to create one user control where grid generates dynamically by passing datatable as a datasource. Here if one of my columns is GridDropDownColumn then on editing, dropdown should be displayed by setting datatable as a datasource that will be passed by aspx page. But it is not displaying in edit mode. Anybody can suggest me how to do it?? and also in edit mode user can enter his custom value.
P. N. grid has to be generated dynamically and I have to create it in Page_Load event of user control

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Nov 2008, 09:27 AM
Hello Anu,

I tried the same scenario at my end and it works as expected. Have you set the EditMode property for the MasterTableView dynamically in the ascx.cs. If not, try setting it as shown below. To enter custom value you can set the DropDownControlType for GridDropDownColumn as RadComboBox and set the combobox's AllowCustomText property as shown in the example.
ascx.cs:
 protected void Page_Init(object sender, EventArgs e) 
    { 
        RadGrid grid = new RadGrid(); 
        grid.ID = "RadGrid2"
        grid.MasterTableView.EditMode = GridEditMode.InPlace; 
        grid.AutoGenerateEditColumn = true
        grid.DataSourceID = "SqlDataSource1"
        grid.ItemDataBound += new GridItemEventHandler(grid_ItemDataBound); 
 
        GridDropDownColumn dropdowncolumn = new GridDropDownColumn(); 
        dropdowncolumn.UniqueName = "DropDown"
        dropdowncolumn.HeaderText = "DropDown"
        dropdowncolumn.DropDownControlType = GridDropDownColumnControlType.RadComboBox; 
        grid.MasterTableView.Columns.Add(dropdowncolumn); 
 
        PlaceHolder1.Controls.Add(grid); 
    } 
 
    void grid_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            RadComboBox ddl = (RadComboBox)editItem["DropDown"].Controls[0]; 
            ddl.DataSource = ""; //set the datasource here 
            ddl.AllowCustomText = true
             
        } 
    } 

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