Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Combobox > Unable to populate RadComboBox in RadGrid Edit form
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered Unable to populate RadComboBox in RadGrid Edit form

Feed from this thread
  • John avatar

    Posted on Mar 22, 2011 (permalink)

    I'm trying to populate a RadComboBox in a RadGrid edit form, and I can't seem to get it to work.
    Here's the relevant code...

    Thanks!
    John

    <EditFormSettings EditFormType="Template">
        <FormTemplate>
            <telerik:RadComboBox ID="SecFlag_RadComboBox" runat="server" SelectedValue='<%# Bind("secflag") %>' DataValueField="seclevel" DataTextField="description" tabIndex="4">
            </telerik:RadComboBox>
         </FormTemplate>
    </EditFormSettings>
     
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            BindToDataTable(DirectCast(RadGrid1.FindControl("SecFlag_RadComboBox"), RadComboBox))
        End If
    End Sub
         
    Private Sub BindToDataTable(ByVal combo As RadComboBox)
        Dim Atl As New Atlantis
        combo.DataSource = Atl.getSecLevels()
        combo.DataTextField = "description"
        combo.DataValueField = "seclevel"
        combo.DataBind()
    End Sub

  • Posted on Mar 23, 2011 (permalink)

    Hello John,

    You can try the following code snippet in ItemCreated event to achieve your scenario.
    C#:
    Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs)
        If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then
            Dim editform As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
            Dim rdcombo As RadComboBox = DirectCast(editform.FindControl("SecFlag_RadComboBox"), RadComboBox)
            Bind(rdcombo)
        End If
    End Sub
    Private Sub Bind(rdcombo As RadComboBox)
        rdcombo.DataSource = SqlDataSource1
        rdcombo.DataTextField = "description"
        rdcombo.DataValueField = "seclevel"
        rdcombo.DataBind()
    End Sub

    Thanks,
    Shinu.

  • John avatar

    Posted on Mar 23, 2011 (permalink)

    Thanks! The combo box is now being populated, but how do I set the selected value???

    I tried using rdcombo.SelectedValue = editform.SavedOldValues("secflag") but that doesn't work.

    How do I reference the radGrid item values?

  • John avatar

    Posted on Mar 23, 2011 (permalink)

    I was able to set the selected value with:

    SelectedValue='<%#DataBinder.Eval(Container.DataItem, "secflag")%>'

    My question now is, when I get the values in my RadGrid1_UpdateCommand event, like this:

            Dim gridediteditem As GridEditFormItem = CType(e.Item, GridEditFormItem)
            Dim newValues As Hashtable = New Hashtable
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, gridediteditem)

    all of the values are being returned except for my radcombobox. How do I get the value???


    Thanks,
    John

  • John avatar

    Posted on Mar 24, 2011 (permalink)

    Got it!

    Here's what worked...

            Dim cbsecflag As New RadComboBox
            cbsecflag = gridediteditem.FindControl("SecFlag_RadComboBox")
            Dim secflag As String
            secflag = cbsecflag.SelectedValue

    Thanks for the help!

  • Posted on Mar 24, 2011 (permalink)

    Hello John,

    Please try using Bind (is for two way binding) instead of DataBinder.Eval (is for one way binding)
    aspx:
    <telerik:RadComboBox ID="RadCombo1r" runat="server" ... SelectedValue='<%# Bind("secflag") %>'... >
    </telerik:RadComboBox>

    Thanks,
    Shinu.

  • John avatar

    Posted on Mar 24, 2011 (permalink)

    That doesn't work, Shinu.

    It gives me the error: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

  • Kalina Kalina admin's avatar

    Posted on Mar 25, 2011 (permalink)

    Hello John,

    This error can occur if you use RadComboBox with Load On Demand enabled and you try to set the SelectedValue of the control via databinding expression.
    You can find more details about this issue at the "Load On Demand RadComboBox inside an EditItemTemplate of RadGrid" Code Library.

    All the best,
    Kalina
    the Telerik team

  • John avatar

    Posted on Mar 25, 2011 (permalink)

    Load-On-Demand is not set for the control.

    The EnableLoadOnDemand property is False for the RadComboBox

  • Kalina Kalina admin's avatar

    Posted on Mar 30, 2011 (permalink)

    Hello John,

    In your post from 3/24/2011 you mention that you have succeeded to overcome the issue.
    Does it still persist?
    Can you provide us more details about your implementation and some sample working code?

    Regards,
    Kalina
    the Telerik team

  • John avatar

    Posted on Mar 31, 2011 (permalink)

    Here's what I ended up with...

    In my edit template:

    <telerik:RadComboBox ID="SecFlag_RadComboBox" runat="server" tabIndex="4" SelectedValue='<%#DataBinder.Eval(Container.DataItem, "secflag")%>' >
    </telerik:RadComboBox>

    and in my code behind:

    Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
        If TypeOf (e.Item) Is GridEditFormItem And e.Item.IsInEditMode Then
            Dim editform As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
            Dim rdcombo As RadComboBox = DirectCast(editform.FindControl("SecFlag_RadComboBox"), RadComboBox)
            BindComboToDataTable(rdcombo)
        End If
    End Sub
     
    Private Sub BindComboToDataTable(ByVal rdcombo As RadComboBox)
        Dim Atl As New Atlantis
        rdcombo.DataSource = Atl.getSecLevels()
        rdcombo.DataTextField = "description"
        rdcombo.DataValueField = "seclevel"
        rdcombo.DataBind()
    End Sub

  • Kalina Kalina admin's avatar

    Posted on Apr 5, 2011 (permalink)

    Hello John,

    Thank you for posting your solution for the community.

    All the best,
    Kalina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Combobox > Unable to populate RadComboBox in RadGrid Edit form