Hello to all
I have one question I think it will be very simple to answer to most of you
This code on a click of Button1 puts in Label1 what is selected in ListBox1 (sorry if I'm not ussing the correct verbs to describe actions, but I'm sure you can understand me or you can read it from the code).
CODE
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = ListBox1.SelectedItem.Text;
}
When I load the page and select something from the ListBox, everything works fine, but when nothing is selected error page is displayed. Is there another way to solve it or do I need an "if" statement? I tried with "if" but I'm not sure what to evaluate and with what exactly. I tried
CODE
if (ListBox1.SelectedItem.Selected == false)
and similar variatinos (null), but it's not working.
Error I get in any case is this:
"Exception Details: System.NullReferenceException: Object reference not set to an instance of an object."
Can you please help me out?
Thank you!