
Can you help me shed some light on the following issue?
Problem:
I have a grid with in-place edit and three records. One column is a griddropdowncolumn. When the grid loads, the values are not displayed for this column.
When I enter the edit mode, values are rendered in this column.
Case A:
If I press the edit button on the first record the dropdown is populated, the correct value is selected in the dropdown and the remaining two records now have a value displayed in this column. If I cancel the edit and return to the gridview the column no longer displays values in this column for any of the records.
Case B:
If I press the edit button of the middle record the dropdown is populated, the correct value is selected in the dropdown, the first record does not display a value for this column but the third record does display a value for this column. If I cancel the edit and return to the gridview the column no longer displays values in this column for any of the records
Detail about the grid and the GridDropDownColumn:
The grid and its dropdown column are bound to datatables contained within the same dataset.
The griddropdowncolumn is defined as follows:
<telerik:GridDropDownColumn
DataField="Country_code" (field name in the grid source)
GroupByExpression="Country_Code"
HeaderText="Country Code"
SortExpression="Country_Code"
UniqueName="Country_Code"
ListTextField="Name" (field name in dropdown source)
ListValueField="Country_code" /> (field name in dropdown source)
The grid is bound to a datatable in the dataset during the NeedDataSource event.
grdAccounts.DataSource = BusinessAccounts.Tables["Business_Accounts"];
When in EditMode the dropdowncolumn is bound to one of the datatables in the dataset during the ItemDataBound event.
GridEditableItem editedItem = e.Item as GridEditableItem;
GridEditManager editMan = editedItem.EditManager;
GridDropDownColumnEditor editor =
editMan.GetColumnEditor("country_code") as GridDropDownColumnEditor;
editor.DataSource = BusinessAccounts.Tables["Countries"];
editor.DataBind();
editor.SelectedValue = editedItem.GetDataKeyValue("Country_Code").ToString();
The ListValueField and the DataField are the same data type and length.
Thanks for your help.
14 Answers, 1 is accepted

<telerik:GridDropDownColumn DataField="PriorityID" DataSourceID="ldsPriorities" HeaderText="Assignment Priority" ListTextField="ValueName" ListValueField="ValueID" UniqueName="PriorityID"></telerik:GridDropDownColumn>
<asp:LinqDataSource ID="ldsPriorities" runat="server" ContextTypeName="MyDataContext" Select="new (ValueID, ValueName)" TableName="AssignmentPriorities" OrderBy="ValueName"></asp:LinqDataSource>

GridDropDownColumn will be bound to a data source where each item from RadGrid would have its representation as a value in the dropdown column's source. If an item in RadGrid cannot find a matching value in the lookup source, then it defaults to an empty string. Hence, for the proper functioning of GridDropDownColumn, verify that all column values referenced by the DataField attribute matches the column values referenced by the ListValueField attribute.
For more information on how to populate a dropdowncolumn in edit mode go through the following help link
Customize/Configure GridDropDownColumn
Princy.

Back to the original post, I am seeing the same thing with respect to the non-edit mode showing an empty label.
What can be said about Case A vs Case B? It would appear that the RadGrid CAN and IS finding a matching value in the lookup source, but only does so when the grid row above is in edit mode.
I am at a lost, any other ideas?
The behavior you are experiencing is due to the fact that you actually replacing the DataSource for the entire DropDownColumn not just for the current cell. Therefore all cells that are below the one which is in editmode will receive the new datasource. In order to workaround this you can try to temporary store the current datasource, bind the DropDown and then re-assign the datasource, similar to this:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
{ |
//... other code; get the column editor ... |
object tempDataSource = editor.DataSource; |
editor.DataSource = table; |
editor.DataBind(); |
editor.DataSource = tempDataSource; |
} |
} |
Please give it a try and let us know how it went.
Regards,
Rosen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

The work around described would likely work, provided the existing datasource was correct to start with. When this patch was applied we actually lost ground. The following results were found for the three grid rows.
- [blank label - bad]
- edit mode [drop down list - good]
- [blank label - bad]
This patch was rolled back, so I am back at having the rows beneath and edit row working.
- [blank label - bad]
- edit mode [drop down - good]
- [populated label - good]
Humor me as I attempt to re-spin the question. When the datagrid does not have any of the 3 rows in edit mode ... all 3 rows show a blank label.
- [blank label - bad]
- [blank label - bad]
- [blank label - bad]
Of course this nearly rectifies itself when I click on row 2. The result being
- [blank label - bad]
- edit mode [drop down - good]
- [populated label - good]
So, how/where can I set the column datasource besides the ItemDataBound event?
Or, how do I set the datasource for the column when not in edit mode?
Any more ideas?
Thanks!

The work around described would likely work, provided the existing datasource was correct to start with. When this patch was applied we actually lost ground. The following results were found for the three grid rows.
- [blank label - bad]
- edit mode [drop down list - good]
- [blank label - bad]
This patch was rolled back, so I am back at having the rows beneath and edit row working.
- [blank label - bad]
- edit mode [drop down - good]
- [populated label - good]
Humor me as I attempt to re-spin the question. When the datagrid does not have any of the 3 rows in edit mode ... all 3 rows show a blank label.
- [blank label - bad]
- [blank label - bad]
- [blank label - bad]
Of course this nearly rectifies itself when I click on row 2. The result being
- [blank label - bad]
- edit mode [drop down - good]
- [populated label - good]
So, how/where can I set the column datasource besides the ItemDataBound event?
Or, how do I set the datasource for the column when not in edit mode?
Any more ideas?
Thanks!

What I am doing, is expanding the code being used to set the datasource for the drop down. Instead of only setting the datasource, when the row is in edit mode ... i'm setting it every time. - not in love with it, but it helps to expose my problem.
The result is
- [blank - bad]
- [label - good]
- [label - good]
So, how can I do this better and how can I get that first row to use the datasource?
protected void grdAccounts_ItemDataBound(object sender, GridItemEventArgs e) | |
{ | |
if (e.Item is GridEditableItem ) | |
{ | |
foreach (GridColumn col in grdAccounts.MasterTableView.Columns) | |
{ | |
if (col.ColumnType == "GridDropDownColumn") | |
{ | |
GridEditableItem eeditedItem = e.Item as GridEditableItem; | |
GridEditManager editMan = editedItem.EditManager; | |
GridDropDownColumnEditor editor = editMan.GetColumnEditor("country_code") as GridDropDownColumnEditor; | |
editor.DataSource = BusinessAccounts.Tables["Countries"]; | |
//Not sure if this is needed, but when executed on a IsInEditMode = false we generate a null error | |
//if ((e.Item as GridEditableItem).IsInEditMode) | |
//{ | |
// editor.DataBind(); | |
// editor.SelectedValue = editedItem.GetDataKeyValue("Country_Code").ToString(); | |
//} | |
} | |
} | |
} | |
} |
The first item's cell is blank in this case because when ColumnEditor is bound, the first item is already bound. Therefore all except the first item has a value. In your case I suggest you consider using a template column with RadComboBox inside its EditItemTemplate and a Label inside the ItemTemplate, instead of using built-in GridDropDownColumn.
Best regards,
Rosen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

..., but I'm so close to getting the Telerik built-in GridDropDownColumn working. I really do not want to add additional complexity when this GridDropDownColumn is all I need.
"The first item's cell is blank in this case because when ColumnEditor is bound, the first item is already bound."
It would appear that there is an bug in the GridDropDownColumn. When it binds that first item and the later items it acts like it is doing so in error. This incorrect behavior is re-affirmed when I manually correct this binding.
Is there a way I can rebind this first row or override the default (errored) binding behavior?
Is this something I should open a ticket up for?
Thanks!
Tim
The first item is already bound, as the code you are using is inside the event's (ItemDataBound) handler which is fired after the item is databound. GridDropDownColumn executes different logic, creates different controls etc. depending on if it is databound or not. Supplying the DataSource inside ItemDataBound and calling the DataBind method will eventually rebind the GridEditItem's ComboBox, but will not populate the cell's text as they are already created. Therefore you should populate the first item's cell manually. Please have in mind that Column as ColumnEditor's setting are shared among all cells in the current column. Thus all cells will share same DataSource once set.
All the best,
Rosen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

The only difference is that the SQL is stored in the markup. In fact the code-behind is empty.
http://demos.telerik.com/aspnet/Grid/Examples/GeneralFeatures/ColumnTypes/DefaultCS.aspx
Is there a demo that has the SQL defined in the code behind, perhaps using datatables? Putting SQL in our mark-up is not an option for me.
Other than that, I'm close to giving up on using this built-in control.
Thanks again for the continued support.
Tim
In the example in question the DropDownColumn's DataSource is defined statically, thus it is available before grid items are databound. I have attached example which demonstrates how to bind the DropDownColumn inside RadGrid's ItemCreatedEvent. Please give it a spin and let us know if this helps.
Kind regards,
Rosen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

I will try to implement this approach first thing monday and let everyone know if that was the magic bullet.
thanks again for creating the demo!
Tim

Thanks again.