savan kuppast
savan kuppast

Reputation: 21

Display the rows of selected columns by using checkboxlist control

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`

Upvotes: 1

Views: 468

Answers (2)

user1
user1

Reputation: 1065

Build your query like this:

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

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

 query += " from tblProject";

Upvotes: 0

gzaxx
gzaxx

Reputation: 17590

Remove single quotes and bracers:

"select " + CheckBoxList1.SelectedItem.ToString() + " from tblProject"

Upvotes: 2

Related Questions