forum

Home / DeveloperSection / Forums / Search selected checkbox values

Search selected checkbox values

Anonymous User170009-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.


Updated on 10-Dec-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By