Search checkbox values in gridview
Hi,
I have a dropdown list with checkbox in the page and when I select multiple options and search its not returning all the selected values in the grid. It returns only one selected value. Here is the code I use it for search. Any suggestions or change in the code. I have binded one gridview column to that checkbox. Checkbox is present outside the gridview. Any suggestions or change in the code?
<asp:CheckBoxList ID="cblGroup" Style="vertical-align: baseline" runat="server" CssClass="chkbox">
</asp:CheckBoxList>
Below is the code on button search I am trying to fetch the checkbox values
protected void btnSearchGroup_Click(object sender, EventArgs e)
{
string selectedValues = string.Empty;
foreach (ListItem item in cblGroup.Items)
{
if (item.Selected)
selectedValues += item.Value+",";
}
if (selectedValues != string.Empty)
selectedValues = selectedValues.Remove(selectedValues.Length - 1);//To remove the last comma;
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand("select * from AppInvent_Test where Designation in ('" + selectedValues + "')", con);
SqlDataAdapter Adpt = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
Adpt.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}