Finding RadComboBox from OnSelectedIndexChanged

3 posts, 0 answers
  1. Bill
    Bill avatar
    3 posts
    Member since:
    Jul 2011

    Posted 01 Aug 2011 Link to this post

    I am trying to use the Selected index of one RadComboBox help build the query to populate another RadComboBox, they are both in the <EditItemTemplate>.
    I get an Object reference not set to instance of an object when I run this code just adding a RadComboBoxItem without even building the query.

    Protected Sub ItemType_SelectedIndexChanged(ByVal o As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)
            Dim DDL As RadComboBox = TryCast(RadGrid1.FindControl("FlatFileType").Controls(0), RadComboBox)
            Dim RadComboBoxItem1 As New RadComboBoxItem("First Item")
    End Sub

    I am not sure how to correctly access the second radcombobox to be able to populate it.
    Any help is greatly appreciated.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 Aug 2011 Link to this post

    Hello Bill,

    You can access the RadComboBox using NamingContainer property.

    Protected Sub RadComboBox1_SelectedIndexChanged1(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
        Dim combo As RadComboBox = TryCast(sender, RadComboBox)
        Dim item As GridEditableItem = DirectCast(combo.NamingContainer, GridEditableItem)
        Dim combo2 As RadComboBox = DirectCast(item.FindControl("FlatFileType"), RadComboBox)
        'populate 2nd combobox
    End Sub

  3. DevCraft R3 2016 release webinar banner
  4. Rakesh Gupta
    Rakesh Gupta avatar
    12 posts
    Member since:
    Oct 2010

    Posted 02 Aug 2011 Link to this post

    Hello Bill,

    You can use below code to populate the second RadCombo on SelectedIndexChange of First RadCombo.

    Let me know if any concern about this.

    Thanks & Regards,
    Rakesh Gupta
    protected sub cmbCountry_SelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
                  Dim cmbCountry As RadComboBox = (RadComboBox)sender;
                  if (cmbCountry.SelectedValue != "")
                      if (Convert.ToInt32(cmbCountry.SelectedValue) > 0)
                          Dim cmbState As RadComboBox= (RadComboBox)cmbCountry.Parent.FindControl("cmbState");
                  Code to generate Data Source
                          cmbState.DataSource = dataSource;
              catch (Exception ex)
                  throw ex;
Back to Top