I am inserting values in listbox from database & retrieving text on a button click. but I'm getting the following error
Object reference not set to instance of object
so "selecteditem.text" does not get any value on item selected...
String selectemail = "select email_id from [property].[dbo].[user_membership]";
SqlCommand cmd = new SqlCommand(selectemail, con);
cmd.Connection.Open();
ListBox1.DataSource = cmd.ExecuteReader();
ListBox1.DataTextField = "Email_ID";
ListBox1.DataBind();
//on button click//
protected void Button1_Click1(object sender, EventArgs e)
{
ListItem item = new ListItem();
item.Text = ListBox1.SelectedItem.Text;(error comes here)
ListBox2.Items.Add(item.Text);
ListBox1.Items.Remove(item.Text);
...
}