ListItem item = new ListItem();
item.Text = ListBox1.SelectedItem.Text;////(error occured here)
ListBox2.Items.Add(item.Text);
ListBox1.Items.Remove(item.Text);
string usrid = null;
string usridselect = "select user_id from user_membership where email_id ='" + ListBox1.Selected开发者_StackOverflowItem.Text + "'";
SqlConnection sqcon = DBConnection.connectDB();
sqcon.Open();
SqlDataReader sqldr = DBConnection.SelectData(usridselect, sqcon);
if (sqldr.HasRows)
{
while (sqldr.Read())
{
usrid = sqldr[0].ToString();
}
}
sqldr.Close();
I just saw your comment... Try to check if selectedItem != null
if (ListBox1.SelectedItem!=null)
{
/// paste your code here
/// anyway - keep in mind that you refer to a selectedItem in your listbox after
/// you removed it from the according listbox
}
精彩评论