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

problem with attributes and loadondemand

3 Answers 173 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Peter asked on 31 Jul 2008, 10:25 PM

I am using RadComboBox for ASP.NET AJAX
I am trying to set and retrieve a custom attribute for  RadComboBoxes
I have successfully done this with a combobox wuthout loadondemand but I cannot get it to work with loadondemand.
I get the following error
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 454:        BatchSettings.AuthorInitials = wcAuthor.SelectedItem.Attributes("AuthorInitials")
Line 455:        BatchSettings.DepartmentHeader = wcDeptHeader.Text
Line 456: BatchSettings.ClinicName = wcClinic.SelectedItem.Attributes("ClinicName")

Line 454 is the normal RadComboBox which works
Line 456 is the loadondemand RadComboBox which doesn't

I have looked at all the relevant forum posts and dowloaded the sample projects LOD_MultiColumn_CustomAttributes and LOD_MultiColumn_CustomAttributes_Web_UI

Here are some extracts of my code:

Protected Sub wcClinic_ItemsRequested(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) Handles wcClinic.ItemsRequested


End Sub

Private Sub loadClinicItems(ByVal SearchText As String)

Dim Conn As SqlConnection

Dim ConnStr As String

If Session("Conn") Is Nothing Then

ConnStr = Application(


Conn =

New System.Data.SqlClient.SqlConnection(ConnStr)


"Conn") = Conn



Conn = Session(


If Conn.State = System.Data.ConnectionState.Closed Then Conn.Open()

End If

Dim sql As String = "SELECT Code,ClinicDescription,[Name] FROM [vw_Clinics] WHERE Code LIKE '" + SearchText + "%'"

Dim adapter As New System.Data.SqlClient.SqlDataAdapter(sql, Conn)

Dim dt As New DataTable()



wcClinic.DataSource = dt


End Sub

Protected Sub wcClinic_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemEventArgs) Handles wcClinic.ItemDataBound

Dim dr As DataRowView = DirectCast(e.Item.DataItem, DataRowView)

e.Item.Value = dr(


e.Item.Text = dr(



"ClinicName") = dr("Name").ToString()

End Sub

BatchSettings.AuthorInitials = wcAuthor.SelectedItem.Attributes(

"AuthorInitials") 'This works

BatchSettings.DepartmentHeader = wcDeptHeader.Text

BatchSettings.ClinicName = wcClinic.SelectedItem.Attributes(

"ClinicName")'This throws an error

Any help would be much appreciated.

3 Answers, 1 is accepted

Sort by
Top achievements
Rank 1
answered on 31 Jul 2008, 11:03 PM
I have also tried the following syntax:
BatchSettings.ClinicName = wcClinic.Attributes("ClinicName")
This does not throw an error but does not contain any value
Veselin Vasilev
Telerik team
answered on 04 Aug 2008, 12:32 PM
Hi Peter,

You cannot access the SelectedItem property on the server when the combo is in load-on-demand mode.
The only properties you can use in the code-behind are Text and SelectedValue.
This is described at this help topic:
ComboBox items are not accessible on the server-side when loading them on demand

Here is what you can do: subscribe to the OnClientSelectedIndexChanged client-side event, get the attribute of the item and set it as a value to a hidden field. Then, on the server - use the value of the hidden field.

I hope this helps.

Sincerely yours,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Top achievements
Rank 1
answered on 06 Aug 2008, 11:18 AM
Thank you.
Asked by
Top achievements
Rank 1
Answers by
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question