I am using a dropdown field in a RadGrid to edit/save a value to a database field. The edit method is via popup. The dropdown list is populated in code behind with the list of the names associated with the values. This is a general concept used in many business models. The data itself is not important to this discussion, only that I am using name/value pairs. The names should be displayed in the dropdown and the values go back and forth to the database. Here is the aspx code setting up the grid column:
Here's the code behind:
The problem I have is that once the editor.DataSource is set, all the Name values are the same as the Value values, so my SelectedValue is not in the list. I have tried using a NameValueCollection instead of an IList but that had no effect. I also tried using a GridDropDownColumnEditor but that had no effect. Somehow setting the DataSource and doing DataBind causes the dropdown list to be populated with just the Name value. The Name/Value should be different (one the item name, one the item value).
My question is, how do I get the dropdown to populate with the Name/Value pairs?
| <telerik:GridDropDownColumn DataField="StartRndType" Visible="false" HeaderText="<%$ Resources:TCRS, Start %>" |
| EditFormColumnIndex="0"> |
| </telerik:GridDropDownColumn> |
| protected void grdRndPolicy_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
| { |
| // get the editedItem (row) |
| GridEditableItem eeditedItem = e.Item as GridEditableItem; |
| GridEditManager editMan = editedItem.EditManager; |
| // get the record |
| RoundPolicyT dataRecord = e.Item.DataItem as RoundPolicyT; |
| // safety check |
| if (dataRecord == null) |
| return; |
| GridDropDownListColumnEditor editor; |
| // All 7 rounding type dropdowns use the same item list - |
| // it does not appear to be necessary to make a new copy for each control |
| IList<ListItem> items = new List<ListItem>(); |
| items.Add(new ListItem(Resources.TCRS.Forward, "1")); |
| items.Add(new ListItem(Resources.TCRS.Nearest, "2")); |
| items.Add(new ListItem(Resources.TCRS.Backward, "3")); |
| // Start Rnd Type dropdown |
| editor = editMan.GetColumnEditor(_STARTRNDTYPE) as GridDropDownListColumnEditor; |
| editor.DataSource = items; |
| editor.DataBind(); |
| editor.SelectedValue = dataRecord.StartRndType.ToString(); |
My question is, how do I get the dropdown to populate with the Name/Value pairs?