Reputation: 199
So this code worked perfectly fine for another ComboBox
, but even though I changed everything in the code the way it should be it refuses to work now - Different ComboBox
, different source but you know ignoring that it is the same situation.
The code that's in the ComboBox
's Selectionchanged
Event:
ComboBox comboBox = (ComboBox)sender;
string id = comboBox.SelectedValue.ToString();
It is throwing:
Object reference not set to an instance of an object.
On the line with the Selected Value.
Upvotes: 1
Views: 4957
Reputation: 63105
try below
ComboBox comboBox = sender as ComboBox;
if(comboBox!=null && comboBox.SelectedValue != null){
string id = comboBox.SelectedValue.ToString();
}
need to check related other codes to find why SelectedValue
is null.
Upvotes: 1