如果条件处理,如何进入For循环内部

时间:2016-04-29 05:51:24

标签: c# sql asp.net for-loop drop-down-menu

我有一个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() + "'");
                    }
                }
            }

1 个答案:

答案 0 :(得分:3)

只需在放入selectedItemstest变量之前过滤项目。

var selectedItemstest = cmbEmp_Name.Items.Cast<ListItem>()
                        .Where(x => x.Selected && x.Value.ToLower().Contains("processed"))
                        .Select(x => x.Value).ToArray();