system nullreferenceexception dropdownlist

Total Post:110


 1920  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?

  1. Re: system nullreferenceexception dropdownlist

    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


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.