Hi is it possible to do a search based on checkboxes, so for instance a user clicks on a few checkboxes and clicks on a search button, how can i then implement this into a stored procedure and does the stored procedure to have a format to take in the values of the chceckbox, if possible can you give me a sample, thank you.

Is it in another control, such as a repeater, datalist, or grid? If so, it gets much more complex. Anyway, it is rather quite simple.

'Lets say you have checkboxes just on the page, not in another control.
'And you wish to do it all same page (without querystrings) and on the server.

<script language="vb" runat="server">
Sub Page_Load
...
...
End Sub

Sub btnSearch_Click(ByVal s as Object, ByVal e as EventArgs)
Dim strSQL As String = "SELECT * FROM Table WHERE "
if chkList1.Items(0).Selected then strSearchVariables &= chkList.1.Items(0).Text & " LIKE ? "
if chkList1.Items(1).Selected then strSearchVariables &= chkList.1.Items(1).Text & " LIKE ? "
if chkList1.Items(2).Selected then strSearchVariables &= chkList.1.Items(2).Text & " LIKE ? "
strSQL &= "LIMIT 100"
'Do your database work here. Now the ? in the sql statement is just because I dont know
'exactly what you are searching for.
'After this all, set your ltlResults to your results. This excepts HTML.
ltlResults = ....
ltlResults.Visible = True
End Sub
</script>

<form runat="server">
<asp:checkboxlist id="chkList1" runat="server">
  <asp:listitem id="option1" runat="server" value="Search1" />
  <asp:listitem id="option2" runat="server" value="Search2" />
  <asp:listitem id="option3" runat="server" value="Search3" />
</asp:checkboxlist>
<asp:button id="btnSearch" onclick="btnSearch_Click" text="Search" runat="server" />
</form>

<asp:Literal id="ltlResults" visible="false" runat="server" />
This article has been dead for over six months. Start a new discussion instead.