Hello....
I am in the process of building a search function for an application (VS2005, ASP.net, VB code, and AJAX functionality).
The user's form has a textbox (for an input string) and two drop-downs. The user would then click on a "Search Now" button, and the data should populate
in a Gridview to the left of the search form. I'm trying to search over an SQL database and need to know how to exactly implement what I have so far:
<
div id="mcb" style="background-color:#2e4b5b; width:195px; height:410px; float:left">
<div id="ht" style="background-color:#1b2c36;padding:10px; border-bottom:solid 1px #fffdff; width:175px;float:left;">
Quick Search
</div>
<div style="clear:both;"></div>
<div style="padding:10px; background-color:#2e4b5b">
<div id="tfta" style="padding:5px 0px 0px 0px">
<b>Vendor Name</b>
<asp:TextBox ID="txtVendorFilter" runat="server"></asp:TextBox>
<div style="font-size:1px; width:150px; height:1px; background-color:#8FA71F"></div><br />
<b>Contract Type:</b>
<asp:dropdownlist ID="ddlContractTypeSearch" runat="server" Width="155px">
<asp:ListItem Value="0">Select...</asp:ListItem>
<asp:ListItem Value="1">Vendor Maintenance</asp:ListItem>
<asp:ListItem Value="2">Consulting Contract</asp:ListItem>
<asp:ListItem Value="3">Hardware License</asp:ListItem>
<asp:ListItem Value="4">Software License</asp:ListItem>
<asp:ListItem Value="5">Statement of Work</asp:ListItem>
<asp:ListItem Value="6">Admin Svcs. Agreement</asp:ListItem>
<asp:ListItem Value="7">Master Service Agreement</asp:ListItem>
</asp:dropdownlist>
<div style="font-size:1px; width:150px; height:1px; background-color:#8FA71F"></div><br />
<b>Sort By:</b>
<asp:DropDownList ID="ddlSortBy" runat="server" Width="155px">
<asp:ListItem Value="0">Select...</asp:ListItem>
<asp:ListItem Value="1">Contract Name</asp:ListItem>
<asp:ListItem Value="2">Contract Type</asp:ListItem>
</asp:DropDownList> <div style="font-size:1px; width:150px; height:1px; background-color:#8FA71F"></div><br />
</div>
<br />
<asp:Button ID="btnUpdateFilter" runat="server" Text="Search" width="120px"/>
<asp:Button ID="btnReset" runat="server" Text="Reset" /></div>
</div>
Here's my select statement used to initially populate the Gridview (set up using the configuration of the Gridview):
SELECT [ContractID], [ContractName], [ContractType], [EffectiveDate], [TerminationDate] FROM [Contract]
Here's my btnUpdateFilter codebehind (VB):
Protected
Sub btnUpdateFilter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdateFilter.Click
Dim strVendorName As String
Dim strContractType As String
Dim strSortBy As String
If txtVendorFilter IsNot "" Then
strVendorName = txtVendorFilter.Text
End If
''''''''''''''''''''''''''''
If ddlContractTypeSearch.SelectedValue = 1 Then
strContractType = "1"
ElseIf ddlContractTypeSearch.SelectedValue = 2 Then
strContractType = "2"
ElseIf ddlContractTypeSearch.SelectedValue = 3 Then
strContractType = "3"
ElseIf ddlContractTypeSearch.SelectedValue = 4 Then
strContractType = "4"
ElseIf ddlContractTypeSearch.SelectedValue = 5 Then
strContractType = "5"
ElseIf ddlContractTypeSearch.SelectedValue = 6 Then
strContractType = "6"
ElseIf ddlContractTypeSearch.SelectedValue = 7 Then
strContractType = "7"
Else
strContractType = "0"
End If
''''''''''''''''''''''''''''''
If ddlSortBy.SelectedValue = 1 Then
strSortBy = "ContractName"
ElseIf ddlSortBy.SelectedValue = 2 Then
strSortBy = "ContractType"
Else
strSortBy = "ContractName"
End If
End
Sub
My question is, "how can I form the proper SQL statement", and then implement it so that my gridview will populate using my generated SQL Statement?
Thank you for the help!!!
-S