Get a handle on a dropdowlist?

  • Thread starter Thread starter Chris Kettenbach
  • Start date Start date
C

Chris Kettenbach

Good Morning All,
How can i get a handle on this drop down list?
public void myDropDown_OnDataBinding(object sender, EventArgs e)
{
DropDownList myDropDown = (DropDownList)sender;
Debug.Write(myDropDown.SelectedItem.Value);
}

gives me an Exception Details: System.NullReferenceException: Object
reference not set to an instance of an object.


Any ideas?

Thanks,
Chris
 
Apparently no item is selected, thus raising the NullRefernceException.
 
Likely myDropDown.SelectedItem is null?

Good Morning All,
How can i get a handle on this drop down list?
public void myDropDown_OnDataBinding(object sender, EventArgs e)
{
DropDownList myDropDown = (DropDownList)sender;
Debug.Write(myDropDown.SelectedItem.Value);
}

gives me an Exception Details: System.NullReferenceException: Object
reference not set to an instance of an object.


Any ideas?

Thanks,
Chris
 
it could be that the SelectedItem object is what raising the null exception..
DropDownList myDropDown = (DropDownList)sender; should be working..

by the way,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top