Is there an easy way to do this?

B

Bishop

I have a gridview for a list of questions. Each question has a CategoryType
(int) assigned to it. There are 6 different Category Types. I have a check
box list of the different categories displayed on the page. It's easy to
assign a variable such as @CategoryType and limit the results to a single
category type but I want people to be able to make multiple selections.
I've tried changeing my query to "Where In (@CategoryType) and interrupting
the select command and setting @CategoryType to 1,2,3 but I get the errror
that it's defined as an Int.

There has to be a good way to do this?
 
G

Göran Andersson

Bishop said:
I have a gridview for a list of questions. Each question has a
CategoryType (int) assigned to it. There are 6 different Category
Types. I have a check box list of the different categories displayed on
the page. It's easy to assign a variable such as @CategoryType and
limit the results to a single category type but I want people to be able
to make multiple selections. I've tried changeing my query to "Where In
(@CategoryType) and interrupting the select command and setting
@CategoryType to 1,2,3 but I get the errror that it's defined as an Int.

There has to be a good way to do this?

Yes, there is a good way. Add another table to the database, which
contains a question id and a category type. Now you can specify any
number of category types to a question, and easily run queries against
the data.

Don't try to store more than one value in a field, that usually ends
badly when you try to actually use the data for something.

How you solve it in the user interface is a different thing, though...
 
B

Bishop

What I'm trying to do is use a gridview with datasource and let the user
choose multiple category types and display all the questions in that
category type.

For instance:
Questions
QuestionID, Question, CategoryTypeID
1, Do you sell balls, 1
2, Were is my stuff, 2
3, Can I return this stuff, 3

CategoryTypes
CategoryTypeID, CategoryType
1, General Question
2, Tracking Info
3, Return Request

I want the customer service person to be able to choose "General Question"
and "Return Request" from a checkbox list, then have the gridview limit the
questions displayed to every question with CategoryTypeID of 1 and 3.

With a general SQL query I would say "Select * from Questions where
CategoryTypeID in (1,3)" I can't seem to get away with making "1,3" a
datasource variable.

I know I can do a code behind datasource or dynamically populate the
datasource select command but I thought there might be a cleaner way to do
this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top