checkboxlist with gridview

ping

Member
Joined
Jun 2, 2010
Messages
10
Programming Experience
3-5
Hi,
I have SQL Database called GAME, table called SET, rows SetID, Name and Match (Match has random int 0 to 10 inclusive)

On a Webform, I have created a checkboxlist with SQLDataSource1 defining SELECT DISTINCT [Match] FROM [SET] ORDER BY [Match] and to return only unique rows.

I have also created a gridview with SQLDataSource2 defining SELECT [Name], [Match] FROM [SET] WHERE ([Match] = @Match) using WHERE clause conltrolID checkboxlist.selectedvalue.

What I am trying to accomplish is a gridview that shows the reults of the selected boxes from the checkboxlist.

What I am getting is a gridview showing just the lowest box selected, not all. How do I get the grid to show all boxes checked?

Can explain more if needed.

Cheers,
James
 
OK, I have changed direction a little bit. And now this won't be a SQL post...

I have created 6 checkboxes... Checkbox0, Checkbox1, Checkbox2, etc... to Checkbox5.

Now I would like to cycle through them in a sort of array or list. Example...

FOR EACH Checkbox in CheckboxList or CheckboxArray
'do something
NEXT

How do I put the Checkboxes in a list or array?
 
Alright, I have got a solution. Just to put closure on this thread, and to enlighten anyone on how this can be done...

I think the problem with Drag and Drop SQLDataSource and getting a checkboxlist to filter a gridview is that the statement obtained is WHERE eg = @eg AND eg = @eg2, etc. Where it needs to be OR, not AND.

So I have written some VB code to overcome this.

Lets say we have a SQL Database called GAME, table called SET, rows SetID, Name and Match (Match has random int 0 to 10 inclusive). And on a WebForm we have a Gridview with SQLDataSource1 attached and CheckBoxes {Checkbox0, Checkbox1, etc... Checkbox9}

VB.NET:
Dim MyCBList As CheckBox() = {CheckBox0, CheckBox1, CheckBox2, CheckBox3, CheckBox4, CheckBox5, CheckBox6, CheckBox7, CheckBox8, CheckBox9}
Dim StrF As String

StrF = ""

For i As Integer = 0 To 9

    If MyCBList(i).Checked = True Then
        If StrF = "" Then
           StrF = "SELECT [Name], [Match] FROM [SET] WHERE (Match = " & i & ")"
        Else
           StrF = StrF & " OR (Match = " & i & ")"
        End If
    End If

Next

If StrF = "" Then
    SqlDataSource1.SelectCommand = "SELECT [Name], [Match] FROM [SET] WHERE (Match >= 0)"
Else
    SqlDataSource1.SelectCommand = StrF
End If
Hope this helps anyone trying to do something similar.

Cheers,
James
 
Back
Top