1

I have a checkboxlist control that is populated by the column names of a table. what I want to do is use a gridview to display only the contents of the particular selected item from checkboxlist.

I have tried the following code, it returns me the same number of records in the table but the content in the grid view is the same as the selected checkboxlist item.

For example, if I select pname(project name) from tblProject(projects table) I get:

pname
pname
pname
pname
pname
pname
pname....

because I have 7 records in tblProject

I use the following code:

`select ('"+CheckBoxList1.SelectedItem.ToString()+"') from tblProject`
1
  • Please, clarify your question, make it more readable to help us, help you. Where do you use, which code? Commented Aug 1, 2013 at 13:33

2 Answers 2

2

Remove single quotes and bracers:

"select " + CheckBoxList1.SelectedItem.ToString() + " from tblProject"
Sign up to request clarification or add additional context in comments.

Comments

0

Build your query like this:

 string query = string.empty
 query += "select ";

 if (CheckBoxList1[0].Selected)
 {
      query += "first_column, ";
 }//and so on

 query += " from tblProject";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.