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

[Solved] Default value for a GridDropDownColumn during Insert

2 Answers 263 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve Wolfe
Top achievements
Rank 1
Steve Wolfe asked on 12 Nov 2009, 01:37 AM
I have a column represented by an GridDropDownColumn.  Its data is really the value of an enum.  I have a datasource that will return name/value pairs for the data for the dropdown column.

What I can't seem to find is how to set the default value for this GridDropDownColumn, when it is displayed for inserting a new item.

The list is populated with all the values from the dataset, but the first item is selected.  Is there a way, other than changing the order of the data coming from the datasource, to set which value should be selected by default for the GridDropDownColumn?

Thanks,
Steve

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 12 Nov 2009, 07:32 AM
Hello Steve,

You can try out the following code to select an item by default in a GridDropDownColumn while inserting in the grid:
c#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) 
        { 
            GridEditFormInsertItem editItem = (GridEditFormInsertItem)e.Item; 
            RadComboBox combo = (RadComboBox)editItem["DropDownColumnUniqueName"].Controls[0]; 
            combo.SelectedIndex = 2;            
        } 
    } 

Thanks
Princy.
0
Steve Wolfe
Top achievements
Rank 1
answered on 12 Nov 2009, 02:20 PM
Exactly what I was looking for.  Thanks!

-Steve
Tags
Grid
Asked by
Steve Wolfe
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Steve Wolfe
Top achievements
Rank 1
Share this question
or