Link to home
Start Free TrialLog in
Avatar of lshane
lshane

asked on

Multiple search boxes on one gridview page

ASP.NET
VB
VS 2005
SQL 2005
NO code-behind page

Hello.  I have a search page that queries a SQL 2005 db for records by "State" from a dropdown list.  That works great.

I would like to, however, add other dropdown lists to search by different parameters (ie. "City", "Type", "County", "Title", etc.).  They can use the same gridview, if possible, or somehow manipulate the Show/Hide parameters to only display certain gridviews based on the Request.Form currently being used.

Either way - I have not been successful with more than one dropdown list control being used on the same page.

Is there a way to do that?
If so, how?
If not - what would be the best way to go about achieving that?

I am new to .NET, but I am comfortable with Classic ASP, if that makes a difference; which, from what I'm seeing with .NET --- it doesn't make a difference.  

I will attach the code for the page, but the link to which I'm referring is:
http://newbw.thebargainwatcher.com/sales2.aspx
<%@ Page Language="VB" %>
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
 
 
<html>
<head>
 
<title>The Bargain Watcher</title>
 
<link rel="stylesheet" type="text/css" href="style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
 
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
 
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
 
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
 
<body onload="MM_preloadImages('images/menu/homeov.gif','images/menu/productsov.gif','images/menu/bboardsov.gif','images/menu/companyov.gif','images/menu/aboutov.gif','images/menu/linksov.gif','images/menu/servicesov.gif','images/menu/photoov.gif','images/menu/helpov.gif','images/menu/faqov.gif','images/menu/supportov.gif','images/menu/emailov.gif','images/menu/topservicesov.gif','images/menu/tophelpov.gif')">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td rowspan="2" width="250"><img src="images/bwlogo2.jpg" width="250" height="90" alt=""/></td>
    <td align="right" valign="top"><a href="http://www.thehungersite.com/" target="_blank"><img src="images/banner.gif" width="468" height="60" border="0" alt=""/></a></td>
  </tr>
  <tr> 
    <td align="right" valign="bottom"><!--#include file="navmain.inc"--></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td colspan="6" bgcolor="#003366"><img src="images/leftend.gif" width="14" height="14" alt=""/></td>
  </tr>
  <tr> 
    <td width="14">&nbsp;</td>
    <td class="leftbg" width="130" valign="top"> 
      <div id="menu">
<!--#include file="leftnav.asp"-->
</div>
 
        <img src="images/checkthis.gif" width="130" height="14" alt=""/><br/>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td align="center" class="leftbg2"> 
            <table width="124" border="0" cellspacing="0" cellpadding="0" align="center">
              <tr> 
                <td align="center" class="nnleft"> 
                  <p><br/>
                    <img src="images/leftpic.jpg" width="80" height="117" alt=""/> </p>                </td>
              </tr>
              <tr>
                <td class="nnleft">This 
                  is where you can add some info about a special product or deal.</td>
              </tr>
            </table>          </td>
        </tr>
      </table>
      <img src="images/checkthis.gif" width="130" height="14" alt=""/> 
      <p align="center"><a href="http://www.ecommercetemplates.com/" target="_blank"><img src="images/leftlogo.gif" width="95" height="62" border="0" alt=""/></a></p>    </td>
    <td bgcolor="#C7D5E7" width="6"><img src="images/clearpixel.gif" width="6" height="1" alt=""/></td>
    <td bgcolor="#C7D5E7" width="100%" valign="top"><img src="images/clearpixel.gif" width="1" height="6" alt=""/> 
      <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#EFF4F4">
        <tr> 
          <td width="24" style="height: 24px"><img src="images/topleft.gif" width="24" height="24" alt=""/></td>
          <td bgcolor="#feae1f" width="24" style="height: 24px"><img src="images/orangeleft.gif" width="25" height="24" alt=""/></td>
          <td bgcolor="#feae1f" width="100%" style="height: 24px"><b>SALES...</b></td>
          <td width="24" style="height: 24px"><img src="images/orangeright.gif" width="24" height="24" alt=""/></td>
        </tr>
        <tr> 
          <td width="24" class="lefttablebg">&nbsp;</td>
          <td width="100%" colspan="2" valign="top"> 
            <table width="98%" border="0" cellspacing="2" cellpadding="2" align="center">
              <tr> 
                <td align="center"> <img src="images/toppic.jpg" width="180" height="95" alt=""/>                </td>
                <td width="60%"> 
                  <p> <b>Search several ways:</b></p>
                  <p>- By State<br/>
                    - By Type<br />
                      - By County<br/>
                    - By Title</p>                  </td>
              </tr>
             
              <tr> 
                <td colspan="2" align="center"> 
                  <hr/>                </td>
              </tr>
              <tr> 
                <td colspan="2" valign="top"> 
                  <table width="100%" border="0" cellspacing="1" cellpadding="1" align="center">
                    <tr> 
                        <td align="left" colspan="3">
                        <form id="form1" runat="server">
                            <table border="1" width="100%">
                                <tr>
                                    <td style="width: 198px">
                                        Search by State:</td>
                                    <td style="width: 204px">
                                        Search by Type:</td>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 198px">
                            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="sale_state" DataValueField="sale_state">
                            </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:salesConnectionString %>"
                                SelectCommand="SELECT DISTINCT [sale_state] FROM [sale_listings]"></asp:SqlDataSource>
                                    </td>
                                    <td style="width: 204px">&nbsp;
                                        <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" DataSourceID="SqlDataSource3"
                                            DataTextField="sale_cat_name" DataValueField="sale_cat_ID" AppendDataBoundItems=true>
                                            <asp:ListItem Text="" Value="" Selected=true />
                                        </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:salesConnectionString %>"
                                            SelectCommand="SELECT * FROM [sale_categories] ORDER BY [sale_cat_name]"></asp:SqlDataSource>
                                    </td>
                                    <td>&nbsp;
                                    </td>
                                </tr>
                            </table>
                            &nbsp; &nbsp; &nbsp;&nbsp;<br />
                            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                                AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None"
                                BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource1" GridLines="Vertical" PageSize="25">
                                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                                <Columns>
                                    <asp:BoundField DataField="sale_title" HeaderText="TITLE" SortExpression="sale_title" />
                                    <asp:BoundField DataField="sale_startdate" HeaderText="START DATE" SortExpression="sale_startdate" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="False"
 >
                                        <HeaderStyle Wrap="False" />
                                    </asp:BoundField>
                                    <asp:BoundField DataField="sale_state" HeaderText="STATE" SortExpression="sale_state" />
                                    <asp:BoundField DataField="sale_city" HeaderText="CITY" SortExpression="sale_city" />
                                    <asp:BoundField DataField="sale_county" HeaderText="COUNTY" SortExpression="sale_county" />
                                </Columns>
                                <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                                <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                                <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                                <AlternatingRowStyle BackColor="Gainsboro" />
                            </asp:GridView>
                            
<script runat=server>
    Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceSelectingEventArgs)
        e.Command.Parameters("@sale_enddate").Value = DateTime.Now
    End Sub
</script>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:salesConnectionString %>"
            SelectCommand="SELECT [sale_title], [sale_state], [sale_startdate], [sale_city], [sale_county] FROM [sale_listings] WHERE (([sale_state] = @sale_state) AND ([sale_enddate] >= @sale_enddate))" 
            onselecting="SqlDataSource1_Selecting">
            <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="sale_state" PropertyName="SelectedValue"
            Type="String" />
            <asp:Parameter Name="sale_enddate" Type="DateTime" />
            </SelectParameters>
            </asp:SqlDataSource>
                            <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" BackColor="White"
                                BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource4"
                                GridLines="Vertical">
                                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                                <Columns>
                                    <asp:BoundField DataField="sale_title" HeaderText="sale_title" SortExpression="sale_title" />
                                    <asp:BoundField DataField="sale_city" HeaderText="sale_city" SortExpression="sale_city" />
                                    <asp:BoundField DataField="sale_state" HeaderText="sale_state" SortExpression="sale_state" />
                                    <asp:BoundField DataField="sale_county" HeaderText="sale_county" SortExpression="sale_county" />
                                    <asp:BoundField DataField="sale_startdate" HeaderText="sale_startdate" SortExpression="sale_startdate" />
                                </Columns>
                                <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                                <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                                <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                                <AlternatingRowStyle BackColor="#DCDCDC" />
                            </asp:GridView>
<script runat=server>
    Protected Sub SqlDataSource4_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceSelectingEventArgs)
        e.Command.Parameters("@sale_enddate").Value = DateTime.Now
    End Sub
</script>                            
                            
                            <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:salesConnectionString %>"
                                SelectCommand="SELECT [sale_title], [sale_city], [sale_state], [sale_county], [sale_startdate] FROM [sale_listings] WHERE ([sale_cat] = @sale_cat) AND ([sale_enddate] >= @sale_enddate))">
                                <SelectParameters>
                                    <asp:ControlParameter ControlID="DropDownList2" Name="sale_cat" PropertyName="SelectedValue"
                                        Type="Int32" />
                                    <asp:Parameter Name="sale_enddate" Type="DateTime" />
                                </SelectParameters>
                            </asp:SqlDataSource>
                            
 
                            <br />
                            </form>
                        </td>
                    </tr>
                    <tr> 
                      <td align="center" colspan="3"></td>
                    </tr>
                    <tr> 
                      <td align="center" colspan="3">&nbsp;</td>
                    </tr>
                  </table>                </td>
              </tr>
            </table>          </td>
          <td class="rightbg">&nbsp;</td>
        </tr>
        <tr> 
          <td width="24"><img src="images/bottomleft.gif" width="24" height="24" alt=""/></td>
          <td colspan="2" class="bottombg">&nbsp;</td>
          <td align="right"><img src="images/bottomright.gif" width="24" height="24" alt=""/></td>
        </tr>
      </table>
      <img src="images/clearpixel.gif" width="1" height="6" alt=""/></td>
    <td bgcolor="#C7D5E7" width="6"><img src="images/clearpixel.gif" width="6" height="1" alt=""/></td>
    <td width="130" class="leftbg" valign="top" align="center"><img src="images/clearpixel.gif" width="130" height="1" alt=""/><br/>
      <br/>
      <img src="images/news.gif" width="128" height="20" alt=""/><br/>
      <table width="120" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr>
          <td class="smaller">
            <table width="124" border="0" cellspacing="0" cellpadding="0" align="center">
              <tr>
                <td class="nnright"> These boxes 
                  can be used to include any type of presentation - you can put 
                  graphics or maybe introduce a part of your site - we've added 
                  different examples here so you can get an idea of what you can 
                  do with them. You can remove all or some of them with a couple 
                  of clicks. </td>
  </tr>
</table>
            
         
            <p><img src="images/rightline.gif" width="130" height="1" alt=""/></p>          </td>
        </tr>
      </table><br/>
	  <img src="images/contactus.gif" width="128" height="20" alt=""/>
	  <table width="120" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr>
          <td class="smaller">
            <table width="124" border="0" cellspacing="0" cellpadding="0" align="center">
              <tr>
                <td class="nnright" align="center"><b>Your 
                  Company Name</b><br/>
                  Address<br/>
                  Zip<br/>
                  Telephone / Fax<br/>
                  <a href="#">Email Us</a></td>
  </tr>
</table>
            
         
            <p><img src="images/rightline.gif" width="130" height="1" alt=""/></p><p align="center"><a href="http://validator.w3.org/check?uri=referer"><img
          src="http://www.w3.org/Icons/valid-xhtml10"
          alt="Valid XHTML 1.0!" height="31" width="88" border="0" /></a>
</p>
<div align="center">
 <a href="http://jigsaw.w3.org/css-validator/">
  <img style="border:0;width:88px;height:31px"
       src="http://jigsaw.w3.org/css-validator/images/vcss" 
       alt="Valid CSS!" border="0" /> </a></div>          </td>
        </tr>
      </table>	   </td>
  </tr>
  <tr> 
    <td width="14">&nbsp;</td>
    <td valign="top" class="leftbg">&nbsp;</td>
    <td class="bottomlinks">&nbsp;</td>
    <td class="bottomlinks" align="center"><a href="index.htm">home</a> 
      &middot; <a href="products.htm">products</a> &middot; <a href="services.htm">services</a> 
      &middot; <a href="help.htm">help</a> &middot; <a href="contact.htm">contact</a></td>
    <td class="bottomlinks">&nbsp;</td>
    <td valign="top" class="leftbg"><img src="images/clearpixel.gif" width="1" height="20" alt=""/></td>
  </tr>
  <tr>
    <td width="14">&nbsp;</td>
    <td valign="top"><img src="images/leftbottom.gif" width="130" height="20" alt=""/></td>
    <td>&nbsp;</td>
    <td class="smaller" align="center">&copy; <%=system.DateTime.Now.Year%> <a href="http://www.thebargainwatcher.com/" target="_blank">www.thebargainwatcher.com</a></td>
    <td>&nbsp;</td>
    <td valign="top"><img src="images/leftbottom.gif" width="130" height="20" alt=""/></td>
  </tr>
</table>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lshane
lshane

ASKER

Hi, strickdd.

Sorry for the delay.  Thanks so much.  I think that will work nicely.


Thanks so much,
Shane