Users Pricing

forum

Home Forums Search selected checkbox values – MindStick

Search selected checkbox values

Anonymous User 1987 09 Dec 2013

I have a dropdown with checkbox list. When I select items and try to display in the grid by clicking the search button, I'm not able to do that.

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();

    }

Can anyone correct me if I have went wrong somewhere.


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md