Configuring GridDropDownColumn
Here is some insight about the mechanism which r.a.d.grid uses to present values for GridDropDownColumn:
//sample select command for grid data-source generation |
//sample select command for GridDropDownColumn data-source generation |
//sample inline GridDropDownColumn definition |
![]() |
Note: Under .NET 2.0 framework the ListDataMember property should be replaced by the DataSourceID property of the corresponding GridDropDownColumn |
- The DataField property points to the column in the grid data-source containing values which will be compared at a later stage with the values available in the column, referenced by the ListValueField property.
- The ListValueField points to the column in the AccessLevel table which will be used as a pointer to retrieve the items for the dropdown in the GridDropDownColumn.
- The ListTextField points to the column in the AccessLevel table from which the grid will extract the values for the dropdown.
- The ListDataMember property points to the AccessLevel table (part of the dataset used for grid data-source) which is the source for the GridDropDownColumn generation.
As you can see, a requirement for the proper functioning of GridDropDownColumn is that all column values referenced by the DataField attribute match the column values referenced by the ListValueField attribute.
If there are values in the GRID_AccessLevelID column of the WebUsers table which do not have corresponding equal values in the DLL_AccessLevelID column of the AccessLevel table, then the grid will display the default first value from the Description column as it will not "know" what is the correct field.
Additional options in GridDropDownColumn on insertion or editing
If you would like to display the additional item in your dropdown list editor both on editing and insertion, you can perform this operation on ItemDataBound. You have to check whether the currently bound item is GridEditableItem and that it is in edit mode. If this condition is met, you can obtain reference to the DropDownList control through the GridDropDownListEditor for the respective column and inject new item in its Items collection.
Adding GridDropDownColumn option on insert/edit
The code below will place new item with text Select Contact Title (colored in red) on first position in the dropdown list editor of GridDropDownColumn. Note that this drop down column has UniqueName DropDownColumn.
|
|
|
|
![]() |
Note: This option will not be persisted/available after the update command. Inserting such item is suitable only for user-friendly message/presentation. |
Customizing the options for GridDropDownColumn on editing
The proper event you need to hook in order to attain this effect is ItemDataBound. You should check if the currently bound item (e.Item) is in edit mode (e.Item.IsInEditMode = true). Then you can find the cell with the dropdown that is currently editable and change the options in the dropdown as per your needs. Here is an example code:|
|
|
|
The code is generalized to work in both InPlace and EditForms editing mode and with any editor similar to GridDropDownListColumnEditor (the default). Note that in order for this to work you should have already set the DropDownColumn properties:
- ListTextField
- ListValueField
which correspond to the properties DataTextField, DataValueField of the dropdown control.

浙公网安备 33010602011771号