I have a RadGrid that has a Templated column containing a RadComboBox that is populated with data from a different datasource that the RadGrid's datasource (Example: You have a RadGrid of Products which can have ParentProducts. When inserting new Products or editing existing Products you want to allow the user to select that the Product has no Parent Product or select a Product from a list of Products as the parent).
I am having an issue with the RadGrid always selecting the ""/Nul/Select an option value even when the user selects a value. The effect of this is that any new item inserted via the RadGrid always has no Parent and any item with a Parent that is edited ends up having no Parent.
Is there something missing or wrong in the code below?
I am having an issue with the RadGrid always selecting the ""/Nul/Select an option value even when the user selects a value. The effect of this is that any new item inserted via the RadGrid always has no Parent and any item with a Parent that is edited ends up having no Parent.
Is there something missing or wrong in the code below?
| <telerik:GridTemplateColumn HeaderText="SectionID" UniqueName="SectionID"> |
| <EditItemTemplate> |
| <telerik:RadComboBox ID="SectionIDEditor" runat="server" AppendDataBoundItems="true" DataValueField="SectionID" DataTextField="SectionName" DataSourceID="SqlDataSource3" Skin="WebBlue" > |
| <Items> |
| <telerik:RadComboBoxItem Value="" Text="Select Parent Section" /> |
| </Items> |
| </telerik:RadComboBox> |
| </EditItemTemplate> |
| <ItemTemplate> |
| <asp:Label ID="SectionIDLabel" runat="server" Text='<%# Eval("SectionID") %>'></asp:Label> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound |
| If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then |
| 'access/modify the edit item template settings here |
| Dim Section As RadComboBox = CType(e.Item.FindControl("SectionIDEditor"), RadComboBox) |
| Section.DataSourceID = "SqlDataSource3" |
| Section.DataBind() |
| If Not DataBinder.Eval(e.Item.DataItem, "SectionID") Is Nothing And IsNumeric(DataBinder.Eval(e.Item.DataItem, "SectionID")) Then |
| ''Section.SelectedValue = DirectCast(DataBinder.Eval(e.Item.DataItem, "SectionID"), Integer) |
| ''Section.Items(0).Attributes("style") = "color: red" |
| 'Section.SelectedValue = DataBinder.Eval(e.Item.DataItem, "SectionID") |
| ''If Section.Items.FindItemByValue("", True).Selected Then |
| ''End If |
| ''Dim ComboItem As RadComboBoxItem |
| ''For Each ComboItem In Section.Items |
| '' If ComboItem.Value.Equals(e.Item.DataItem) Then |
| '' ComboItem.Selected = True |
| '' End If |
| ''Next ComboItem |
| If (Not Session("updatedValue") Is Nothing) Then |
| Section.SelectedValue = Session("updatedValue") |
| End If |
| Else |
| Section.SelectedValue = "" |
| End If |
| End If |
| 'If (TypeOf e.Item Is GridEditableItem AndAlso CType(e.Item, GridEditableItem).IsInEditMode) Then |
| ' 'Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem) |
| ' 'Dim editMan As GridEditManager = editedItem.EditManager |
| ' 'Dim editor As GridTemplateColumnEditor = CType(editMan.GetColumnEditor("SectionID"), GridTemplateColumnEditor) 'in case you have RadComboBox editor for the GridDropDownColumn (this is the default editor), 'you will need to use ComboBoxControl below instead of DropDownListControl 'and add RadComboBoxItems instead of ListItems to the Items collection of the editor |
| ' 'Dim Section As RadComboBox = editor.ComboBoxControl |
| ' Dim Section As RadComboBox = CType(e.Item.FindControl("SectionIDEditor"), RadComboBox) |
| ' 'Section.Items.Insert(0, New RadComboBoxItem("Select Parent Section", "NotSetItem")) |
| ' If Not DataBinder.Eval(e.Item.DataItem, "SectionID") Is Nothing And IsNumeric(DataBinder.Eval(e.Item.DataItem, "SectionID")) Then |
| ' 'Section.SelectedValue = DirectCast(DataBinder.Eval(e.Item.DataItem, "SectionID"), Integer) |
| ' 'Section.Items(0).Attributes("style") = "color: red" |
| ' Section.SelectedValue = DataBinder.Eval(e.Item.DataItem, "SectionID") |
| ' 'If Section.Items.FindItemByValue("", True).Selected Then |
| ' 'End If |
| ' 'Dim ComboItem As RadComboBoxItem |
| ' 'For Each ComboItem In Section.Items |
| ' ' If ComboItem.Value.Equals(e.Item.DataItem) Then |
| ' ' ComboItem.Selected = True |
| ' ' End If |
| ' 'Next ComboItem |
| ' End If |
| 'End If |
| End Sub |