Home > DeveloperSection > Forums > system nullreferenceexception dropdownlist
Jeet Verma
Jeet Verma

Total Post:110

Posted on    January-22-2014 11:47 PM

 C# C# 

 1 Reply(s)
 1432  View(s)
Rate this:

function abc(){

     string Code = (combobox.SelectedItem.Value != null) ? combobox.SelectedItem.Value.ToString() : string.Empty;

     (save function ....)


Anyone knows how to I can proceed with save function if the combobox is null value and it pop up error system null reference exception?

Pravesh Singh

Total Post:412

Posted on    January-23-2014 12:56 AM

Hi Jeet,

You didn't post where you get the NullReferenceException, however it's most likely when you are performing this evaluation

combobox.SelectedItem.Value != null

The ComboBox's SelectedItem property will return null if nothing is selected. If you call the Value property on the null selected item, you'll get a NullReferenceException. What you should be checking is:

combobox.SelectedItem != null

Don't want to miss updates? Please click the below button!

Follow MindStick