I have a combo box in my grid, when I edit the underlying data I want the current data item to be selected in the combo box
in my codebehind I have this
this line
combo.FindItemByValue(DataBinder.Eval(e.Item.DataItem, "CastMemberName").ToString()).Selected = true;
should select the current name in the combo, but it doesnt. The first item in the the combo is always set.
Ive used this method many, many times before and its always worked, yet in this case it wont !
Ive checked the value in CastMemberName and its a valid name that is in the data bound to the combo.
Can anyone see what the problem is ?
<telerik:GridTemplateColumn UniqueName="CastMember" HeaderText="Cast Member" DataField="CastMemberName" |
SortExpression="CastMember" ItemStyle-HorizontalAlign="Left"> |
<ItemTemplate> |
<%#DataBinder.Eval(Container.DataItem, "CastMemberName")%> |
</ItemTemplate> |
<EditItemTemplate> |
<telerik:RadComboBox DataTextField="CastMemberName" Skin="Vista" |
DataValueField="CastMemberName" |
ID="RadComboBoxCastMember" |
runat="server" |
Width="220px" > |
</telerik:RadComboBox> |
</EditItemTemplate> |
<ItemStyle HorizontalAlign="Left"></ItemStyle> |
</telerik:GridTemplateColumn> |
in my codebehind I have this
protected void RadGridCastList_ItemCreated(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridDataItem) |
{ |
if (e.Item.IsInEditMode) |
{ |
GridEditableItem editItem = e.Item as GridEditableItem; |
RadComboBox combo = (RadComboBox)editItem.FindControl("RadComboBoxCastMember"); |
combo.DataTextField = "CastMemberName"; |
combo.DataValueField = "CastMemberName"; |
combo.DataSource = castmanager.CastNames(); - a list of cast member names |
combo.DataBind(); |
try |
{ |
combo.FindItemByValue(DataBinder.Eval(e.Item.DataItem, "CastMemberName").ToString()).Selected = true; |
} |
catch (NullReferenceException ex) |
{ |
combo.SelectedIndex = 0; |
} |
RadNumericTextBox rntb = (RadNumericTextBox)editItem.FindControl("RadNumericTextBoxDisplayOrder"); |
try |
{ |
rntb.DbValue = (int)DataBinder.Eval(e.Item.DataItem, "DisplayOrder"); |
} |
catch (Exception ex2) |
{ |
// |
} |
} |
else |
{ |
} |
} |
} |
this line
combo.FindItemByValue(DataBinder.Eval(e.Item.DataItem, "CastMemberName").ToString()).Selected = true;
should select the current name in the combo, but it doesnt. The first item in the the combo is always set.
Ive used this method many, many times before and its always worked, yet in this case it wont !
Ive checked the value in CastMemberName and its a valid name that is in the data bound to the combo.
Can anyone see what the problem is ?