我有一个MultipleDropdownlist
用户可以从中选择多个项目。
现在我想要的是,只有当FOR LOOP
中选择的项目为dropdownlist
PROCESSED
。
以下是我的代码。
DataTable dtspmonthyear = new DataTable();
ObjPriCon.Open();
var selectedItemstest = cmbEmp_Name.Items.Cast<ListItem>().Where(x => x.Selected).Select(x => x.Value).ToArray();
var resulttest = String.Join(",", selectedItemstest);
var count = selectedItemstest.Length;
str_emp_sel = resulttest;
using (SqlConnection conn = new SqlConnection("ConnectionString"))
{
using (SqlCommand sqcmd = new SqlCommand("select month(a.dt_of_leave)month, year(a.dt_of_leave)year " +
"from emp_mst a where month(a.dt_of_leave) >= month(getdate())-1 and " +
"year(a.dt_of_leave)= case when month(getdate())=1 " +
"then year(getdate())-1 else year(getdate()) end " +
"and emp_card_no IN (" + str_emp_sel + ") order by emp_name", ObjPriCon))
{
SqlDataAdapter damonthyear = new SqlDataAdapter(sqcmd);
damonthyear.Fill(dtspmonthyear);
for (i = 0; i < dtspmonthyear.Rows.Count; i++)
{
CF.ExecuteQuerry("exec Emp_Resign_Allocate_Leave '" + str_emp_sel + "','" + dtspmonthyear.Rows[0]["month"].ToString() + "', '" + dtspmonthyear.Rows[0]["year"].ToString() + "'");
}
}
}
答案 0 :(得分:3)
只需在放入selectedItemstest
变量之前过滤项目。
var selectedItemstest = cmbEmp_Name.Items.Cast<ListItem>()
.Where(x => x.Selected && x.Value.ToLower().Contains("processed"))
.Select(x => x.Value).ToArray();