I have a GridTemplateColumn with a RadComboBox in the EditItemTemplate:
This works fine when I open a row for editing, but when I click 'update', the new selected value from the combobox is not saved in the database. I'm using a simple LinqDataSource (see above). I'm sure I have missed something obvious, but I can't find it.
<telerik:GridTemplateColumn DataField="Priority" DataType="System.Int32" HeaderText="Priority" SortExpression="Priority" UniqueName="Priority"> | ||
<EditItemTemplate> | ||
<telerik:RadComboBox ID="comboPriority" runat="server"></telerik:RadComboBox> | ||
</EditItemTemplate> | ||
</telerik:GridTemplateColumn>
|
The combo is populated in code-behind, in the RadGrid's ItemDataBound event:
public Dictionary<string, int> Priors = new Dictionary<string, int>() |
{ |
{ "Low", -1 }, |
{ "Normal", 0 }, |
{ "High", 1 } |
}; |
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
{ |
GridEditableItem eeditItem = e.Item as GridEditableItem; |
RadComboBox combo = (RadComboBox)editItem.FindControl("comboPriority"); |
combo.DataSource = Priors; |
combo.DataTextField = "Key"; |
combo.DataValueField = "Value"; |
combo.DataBind(); |
combo.SelectedValue = ((SWcom.Task)editItem.DataItem).Priority.GetValueOrDefault(0).ToString(); |
} |
} |
Also, is there a more elegant or better way to get a key/value list bound to a combobox instead of a Dictionary?
Thanks!
oVan