我正在使用带有复选框的下拉菜单,我可以在其中选择多个项目,并且我正在使用它将数据插入到我的详细信息视图中。我的问题是,如果我从下拉列表中选择了多个项目,即使我从下拉框中选择了多个项目,它也只会插入第一个被选中的项目。我在这里做错了什么?请。帮助
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
foreach (ListItem listItem in cblCustomerList.Items)
{
if (listItem.Selected)
{
string GroupName = cblCustomerList.SelectedValue;
sqlcon.Open();
string eno = ((TextBox)DetailsView1.FindControl("txteno")).Text.ToString();
string empname = ((TextBox)DetailsView1.FindControl("txtempname")).Text.ToString();
string sal = ((TextBox)DetailsView1.FindControl("txtsal")).Text.ToString();
SqlCommand cmd = new SqlCommand("select eno from emp where eno = '" + eno + "'", sqlcon);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
lblmsg.Text = "Employee No already exists";
}
else
{
dr.Close();
sqlcmd = new SqlCommand("insert into emp values('" + eno + "', '" + empname + "','" + sal + "' , '" + GroupName + "')", sqlcon);
sqlcmd.ExecuteNonQuery();
// DetailsView1.ChangeMode(DetailsViewMode.Insert);
}
sqlcon.Close();
// LoadDet();
}
}
}