This is a migrated thread and some comments may be shown as answers.

populate combobox in default edit form of grid

1 Answer 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Clive Hoggar
Top achievements
Rank 1
Clive Hoggar asked on 02 Nov 2011, 10:52 PM
I feel sure this is very straightforward but I am just not getting it.

I have a grid column and code behind as a test approach like this:

<telerik:GridTemplateColumn DataField="Category" HeaderText="CatID" 
            SortExpression="Category" UniqueName="Category">
            <EditItemTemplate>
                  
                <telerik:RadComboBox ID="RadComboBox1" Runat="server">
                </telerik:RadComboBox>
                  
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="CategoryLabel" runat="server" Text='<%# Eval("Category") %>'></asp:Label>
            </ItemTemplate>
            <HeaderStyle Width="150px" />
        </telerik:GridTemplateColumn>
  
  
Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs)
        If (TypeOf e.Item Is GridEditableItem) AndAlso (e.Item.IsInEditMode) Then
            Dim edititem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
            Dim RCB1 As RadComboBox = DirectCast(edititem("Category").Controls(0), RadComboBox)
  
            Dim item1 As New RadComboBoxItem()
            item1.Text = "BibleStudy"
            item1.Value = "Bible Study"
            RCB1.Items.Add(item1)
  
        End If
  
    End Sub

But the item does not show up in the combo box, and there are no error messages. 

What am I doing wrong?

Thanks for some pointers...

Clive

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Nov 2011, 05:09 AM
Hello Clive,

Try the following code snippet.
VB:
Protected Sub grid_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridEditableItem AndAlso TryCast(e.Item, GridEditableItem).IsInEditMode Then
        Dim edititem As GridEditableItem = TryCast(e.Item, GridEditableItem)
        Dim combo As RadComboBox = DirectCast(edititem.FindControl("RadComboBox1"), RadComboBox)
        Dim item As New RadComboBoxItem()
        item.Text = "BibleStudy"
        item.Value = "BibleStudy"
        combo.Items.Add(item)
    End If
End Sub

Thanks,
Shinu.
Tags
Grid
Asked by
Clive Hoggar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or