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

Finding RadComboBox from OnSelectedIndexChanged

2 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 01 Aug 2011, 03:41 PM

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")
        DDL.Items.Add(RadComboBoxItem1)
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Aug 2011, 05:35 AM
Hello Bill,

You can access the RadComboBox using NamingContainer property.

VB.NET:
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

Thanks,
Shinu.
0
Rakesh Gupta
Top achievements
Rank 2
answered on 02 Aug 2011, 10:09 AM
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)
      {
          try
          {
              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;
                      cmbState.DataBind();
                  }
              }
          }           
          catch (Exception ex)
          {
              throw ex;
          }
      }
Tags
Grid
Asked by
Bill
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Rakesh Gupta
Top achievements
Rank 2
Share this question
or