---
title: "Search selected checkbox values"  
description: "Search selected checkbox values"  
author: "Anonymous User"  
published: 2013-12-09  
updated: 2013-12-10  
canonical: https://www.mindstick.com/forum/1753/search-selected-checkbox-values  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Search selected checkbox values

I have a [dropdown](https://www.mindstick.com/articles/263/ajax-toolkit-dropdownextender-in-asp-dot-net) with [checkbox](https://www.mindstick.com/articles/291/how-should-use-checkbox-control-in-vb-dot-net) list. When I select items and try to display in the grid by clicking the [search button](https://answers.mindstick.com/qa/34597/what-is-site-search-button), I'm not able to do that.

protected void btnSearchEmpCode_Click(object sender, EventArgs e)

{

string selectedValues = string.Empty;

foreach ([ListItem](https://www.mindstick.com/forum/23267/insert-a-listitem-to-a-dropdownlist) item in cblEmpCode.Items)

{

if (item.Selected)

selectedValues += "'" + item.Value + "',";

}

if (selectedValues != string.Empty)

selectedValues = selectedValues.Remove(selectedValues.Length - 1);

[SqlConnection](https://www.mindstick.com/forum/1209/sqlconnection-sqlcommand-sqldatareader-idisposable) con = new SqlConnection(strcon);

[SqlCommand](https://www.mindstick.com/forum/91/difference-between-sqlcommand-and-sqlcommandbuilder) cmd = new SqlCommand("SELECT *FROM Details WHERE Emp_Code IN (" + selectedValues + ")", con);

[SqlDataAdapter](https://www.mindstick.com/interview/33991/what-is-sqldataadapter) Adpt = new SqlDataAdapter(cmd);

[DataTable](https://www.mindstick.com/blog/195/datatable-in-ado-dot-net) dt = new DataTable();

Adpt.Fill(dt);

AIGrids.DataSource = dt;

AIGrids.DataBind();

}

Can anyone correct [me if](https://answers.mindstick.com/qa/50259/tell-me-if-your-system-is-infected-by-a-virus-how-you-will-recover-the-data) I have [went wrong](https://answers.mindstick.com/qa/94671/how-do-i-create-a-google-account-when-the-page-keeps-showing-me-a-message-that-something-went-wrong) somewhere.

## Replies

### Reply by Anonymous User

Hi Chintoo,\

Problem 1: you are adding single quotes ' to Emp_Code column .

Problem 2: you are not giving space between * and FROM

## Try This:

```
protected void btnSearchEmpCode_Click(object sender, EventArgs e){    string selectedValues = string.Empty;    foreach (ListItem item in cblEmpCode.Items)    {        if (item.Selected)            selectedValues +=  item.Value + ",";    }     if (selectedValues != string.Empty)        selectedValues = selectedValues.Remove(selectedValues.Length - 1);    SqlConnection con = new SqlConnection(strcon);    SqlCommand cmd = new SqlCommand("SELECT * FROM Details WHERE Emp_Code IN (" + selectedValues + ")", con);    SqlDataAdapter Adpt = new SqlDataAdapter(cmd);    DataTable dt = new DataTable();    Adpt.Fill(dt);    AIGrids.DataSource = dt;    AIGrids.DataBind();}
```


---

Original Source: https://www.mindstick.com/forum/1753/search-selected-checkbox-values

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
