Get a handle on a dropdowlist?

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
 
S

Steve C. Orr [MVP, MCSD]

Apparently no item is selected, thus raising the NullRefernceException.
 
S

Siva M

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
 
G

Guest

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top