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

GridDropDownColumn Edit

8 Answers 277 Views
Grid
This is a migrated thread and some comments may be shown as answers.
etu
Top achievements
Rank 1
etu asked on 19 Oct 2008, 12:26 PM
Hi,

I little bit confused,  the problem is that i have some users , i am binding these user to Grid with datatable.In edit mode i want to change the selected user's role.I mean, role column must be dropdowncolumn and when i bind grid, dropdowncolumn must show the user's current roles.But in edit mode this column must show all the avaliable role types that are stored in database.I hope, i can explain it.Thank you.

8 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 20 Oct 2008, 04:23 AM
Hi,

You can use a GridDropDownColumn which will help you achieve the required scenario. In the normal mode of the grid, the GridDropDownColumn displays data just as a GridBoundColumn whereas in the edit mode of the grid, the column displays all the available options in a dropdownlist.
aspx:
<telerik:GridDropDownColumn DataSourceID="SqlDataSource1" DataField="Users" ListTextField="Users" ListValueField="Users" HeaderText="Users" UniqueName="Users" DropDownControlType="RadComboBox"
   </telerik:GridDropDownColumn>  

For more Information on column types refer this help link.
Thanks
Princy.
0
etu
Top achievements
Rank 1
answered on 20 Oct 2008, 10:26 AM
Hi,

But i dont have any SourceId, i am populating data with dataTable from code.
And i am binding it on PageLoad.That's why, i confused.i can populate it with datatable.when it is in edit mode, how can i populate dropdowncolumn with new datas.

Regards,
Etu
0
etu
Top achievements
Rank 1
answered on 21 Oct 2008, 06:27 AM
I solved it :), thank you very much.
0
SeRiAlKiL
Top achievements
Rank 1
answered on 21 Oct 2008, 08:31 AM
Can you please post how you solved it? I am working on a similar thing

Thank you
0
etu
Top achievements
Rank 1
answered on 22 Oct 2008, 10:36 AM
Hi, sorry for late responding,

On ItemDataBound event i wrote this code.

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("RoleName") as GridDropDownColumnEditor;


            string selectedValue = editor.SelectedValue;
            // change the data source for ContactTitle with custom code here

            DataTable table = DatabaseHelper.GetCorprateUserRoles(showAdmins);

            editor.DataSource = table;
            editor.DataBind();
            editor.SelectedValue = selectedValue;


         
        }

0
SeRiAlKiL
Top achievements
Rank 1
answered on 22 Oct 2008, 10:58 AM
Really thanks! I'll work on it now
0
Ali
Top achievements
Rank 1
answered on 16 Dec 2008, 07:48 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 your code. 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
0
Princy
Top achievements
Rank 2
answered on 17 Dec 2008, 05:29 AM
Hello Ali,

The GridDropDownColumn is designed to be used mainly with DataTables in order to easily map and generate their dropdown items values using the DataField/ListValueField/DataSourceID/ListDataMember values of the column. If you want to bind the dropdowncolumn in normal mode, you can try binding the Literal present in the GridDropDownColumn during normal grid mode as shown below.
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["ColumnUniqueName"].Controls[0];             
            litrl.Text = DataBinder.Eval(item.DataItem, "DataFieldName").ToString(); 
        }  
   }  

Another suggestion is that, for custom objects collections or when you want to change the source of the dropdowncolumn dynamically, you can consider replacing the GridDropDownColumn with template column holding a DropDownList in its edit template.

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