ComboBox / Related ComboBoxes exemple
all work perfectly but now i tri tu put in session the value off the 3 combobox
the 1 work perfectly but the other do this message :
System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
my code :
Protected Sub Loadvoiture()
Dim connection As SqlConnection = CreateConnection()
Dim adapter As New SqlDataAdapter("SELECT * FROM MAKE ORDER By Make", connection)
Dim dt As New DataTable()
adapter.Fill(dt)
RadComboBox1.DataTextField =
"Make"
RadComboBox1.DataValueField =
"Makecode"
RadComboBox1.DataSource = dt
RadComboBox1.DataBind()
'insert the first item
RadComboBox1.Items.Insert(0,
New RadComboBoxItem("- Slectionnez une marquent -"))
End Sub
Protected Sub LoadModele(ByVal MakecodeID As String)
Dim connection As SqlConnection = CreateConnection()
Dim adapter As New SqlDataAdapter("SELECT * FROM MODEL WHERE Makecode=@Makecode ORDER By Model asc", connection)
adapter.SelectCommand.Parameters.AddWithValue(
"@Makecode", MakecodeID)
Dim dt As New DataTable()
adapter.Fill(dt)
For Each row As DataRow In dt.Rows
Dim item As New RadComboBoxItem()
tem.Text = row(
"Model").ToString() & " ( " & row("Model_Year_From").ToString() & " - " & row("Model_Year_Till").ToString() & " ) "
item.Value = row(
"ModelCode").ToString()
RadComboBox2.Items.Add(item)
Next
End Sub
Protected Sub LoadType(ByVal ModelCodeID As String)
Dim connection As SqlConnection = CreateConnection()
Dim adapter As New SqlDataAdapter("SELECT * FROM TYPE WHERE ModelCode=@ModelCode ORDER By ModelCode", connection)
adapter.SelectCommand.Parameters.AddWithValue(
"@Modelcode", ModelCodeID)
Dim dt As New DataTable()
adapter.Fill(dt)
RadComboBox3.DataTextField =
"Type"
RadComboBox3.DataValueField =
"TypeCode"
RadComboBox3.DataSource = dt
RadComboBox3.DataBind()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'------------------------after this WORK
Session(
"marque") = RadComboBox1.SelectedItem.Text
Session(
"marqueID") = RadComboBox1.SelectedItem.Value
'------------------------after this NOT WORK
Session(
"modelev") = RadComboBox2.SelectedItem.Text
Session(
"modelevID") = RadComboBox2.SelectedItem.Value
Session(
"typev") = RadComboBox3.SelectedItem.Text
Session(
"typevID") = RadComboBox3.SelectedItem.Value
End Sub
this code not work impossible to put the selected value of RadComboBox2 and RadComboBox3 in session
why ? the first RadComboBox1 session work perfectly !
Thanks for you help