I defined a listbox as GridTemplateColumn.
It populates the available selections fine, but I could not get it to select with the value from database automatically without additional code in ItemDataBound.
Also am I defining DataField correctly in both template and listbox itself?
<telerik:GridTemplateColumn UniqueName="colLstOpt" HeaderText="Rebalance" DataField="Opt_In" DataType="System.String" >
<ItemTemplate>
<asp:ListBox ID="lstOpt" runat="server" DataSourceID="XmlDataSource1" DataField="Opt_In" SelectionMode="Single" DataTextField="Name" DataValueField="Value"></asp:ListBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
Is it supposed to work with above code without having to code in ItemDataBound below?
Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
If (TypeOf e.Item Is GridEditableItem AndAlso CType(e.Item, GridEditableItem).IsInEditMode) Then
Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
CType(editedItem.FindControl("lstOpt"), ListBox).SelectedValue = e.Item.DataItem("Opt_In").ToString
End If
End Sub
It populates the available selections fine, but I could not get it to select with the value from database automatically without additional code in ItemDataBound.
Also am I defining DataField correctly in both template and listbox itself?
<telerik:GridTemplateColumn UniqueName="colLstOpt" HeaderText="Rebalance" DataField="Opt_In" DataType="System.String" >
<ItemTemplate>
<asp:ListBox ID="lstOpt" runat="server" DataSourceID="XmlDataSource1" DataField="Opt_In" SelectionMode="Single" DataTextField="Name" DataValueField="Value"></asp:ListBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
Is it supposed to work with above code without having to code in ItemDataBound below?
Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
If (TypeOf e.Item Is GridEditableItem AndAlso CType(e.Item, GridEditableItem).IsInEditMode) Then
Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
CType(editedItem.FindControl("lstOpt"), ListBox).SelectedValue = e.Item.DataItem("Opt_In").ToString
End If
End Sub