我有很多个复选框 大约100个 是条件
用来查询 怎么才可以可比把 选种的复选框就是Checked=true的便利出来然后
组成sql语句 来查询

解决方案 »

  1.   


           string str = "";//复选框前面的select语句
            string[] strItem =new string[CheckBoxList1.Items.Count];
            for (int i = 0; i < CheckBoxList1.Items.Count; i++)
            {
                if (CheckBoxList1.Items[i].Selected)
                {
                    str += strItem[i]+"='"+CheckBoxList1.Items[i].Value+"',";
                }
            }
    用一个checkboxlist吧,那样好遍历一些,读取也非常的方便!
      

  2.   

    string sql = "SELECT * FROM yourTable WHERE 1=1 ";
    foreach(ListItem item in CheckBoxList1.Items) {
       if(item.Selected) {
            // as following
           // sql += item.Value > someValue ....
       }
    }