I've got a page that should change, depending on which item on the dropdownlist is chosen. Unfortunately, the page seems to be ignoring whatever's selected and just clinging on to the first item on the list. I'm sure I'm missing something blindingly obvious, but any help would be greatly appreciated.

The dropdownlist is generated in a Page_Load using the following:

TheSQL = New SqlCommand("Select CatID, CatName from RSG_Category order by CatName", objConn)
  TheResults = TheSql.ExecuteReader
  CatID.DataValueField = "CatID"
  CatID.DataTextField = "CatName"
  CatID.DataSource=TheResults
  CatID.DataBind()
  TheSQL.dispose()
  TheResults.dispose()
  objConn.close()

While the list itself, plus the results table, is generated as follows:

<form runat="server">
            <table border="0" cellpadding="0" cellspacing="5" width="98%" align="center">
              <tr>
                <td>
                  <a href="menu.aspx"><img src="images/backbutton.gif" alt="Back" border="0" align="left">Back</a><BR><BR>
                </td>
              </tr>
              <tr>
                <td>
                  <img src="images/contractor.gif" alt="Contractors" align="left">Current Contractors for <%=session("LogInName")%><BR><BR>
                  <asp:dropdownlist id="CatID" name="CatID" runat="server" />&nbsp;<asp:Button Text="GO" OnClick="Submit" runat="server"/>
                </td>
              </tr>
              <tr>
                <td>
                <asp:GridView ID="GridViewCompanyMany" runat="server" AutoGenerateColumns="False" DataKeyNames="ContID" DataSourceID="SqlDataSource1" AllowSorting="True" AllowPaging="True" width="100%" borderwidth="1" borderstyle="solid" bordercolor="#CCCCCC">
                  <HeaderStyle HorizontalAlign="Left" backcolor="#9D9D9D" forecolor="#FFFFFF" />
                  <Columns>
                    <asp:HyperLinkField DataNavigateURLFields="ContID" DataNavigateUrlFormatString="contractorview.aspx?ContID={0}" DataTextField="ContName" HeaderText="Contractor" SortExpression="ContSName" />
                    <asp:BoundField DataField="ContEmail" HeaderText="Email" SortExpression="ContEmail" />
                    <asp:BoundField DataField="ContAvDate" HeaderText="Date Available" SortExpression="ContAvDate" />
                    <asp:BoundField DataField="ContLocation" HeaderText="Location" SortExpression="Location" />
                  </Columns>
                  <PagerSettings Mode="NumericFirstLast" FirstPageText="First" LastPageText="Last" />
                  <rowstyle backcolor="#FFFFFF"/>
                  <alternatingrowstyle backcolor="#CCCCCC"/>
                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="Server" ConnectionString="<%$ConnectionStrings:TheLocalServer%>" ProviderName="<%$ ConnectionStrings:TheLocalServer.providerName%>" SelectCommand="Select ContID, ContFName + ' ' + ContSName as ContName, ContSName, ContEmail, ContAvDate, ContLocation from RSG_Contractor where (Cat1=@CatID or Cat2=@CatID or Cat3=@CatID or Cat4=@CatID or Cat5=@CatID)">
                  <SelectParameters>
                    <asp:ControlParameter ControlID="CatID" Name="CatID" PropertyName="SelectedValue" Type="Int32" />
                  </SelectParameters>
                </asp:SqlDataSource>
                </td>
              </tr>
            </table>
</form>

Try placing the page load code inside the if condition as below:

If Not (IsPostBack) Then

     TheSQL = New SqlCommand("Select CatID, CatName from RSG_Category order by CatName", objConn)
  TheResults = TheSql.ExecuteReader
  CatID.DataValueField = "CatID"
  CatID.DataTextField = "CatName"
  CatID.DataSource=TheResults
  CatID.DataBind()
  TheSQL.dispose()
  TheResults.dispose()
  objConn.close()      

        End If

Ah! That's got it; thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.