943,745 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1210
  • ASP.NET RSS
Aug 27th, 2008
0

Dropdownlist Problems

Expand Post »
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:
ASP.NET Syntax (Toggle Plain Text)
  1. TheSQL = New SqlCommand("Select CatID, CatName from RSG_Category order by CatName", objConn)
  2. TheResults = TheSql.ExecuteReader
  3. CatID.DataValueField = "CatID"
  4. CatID.DataTextField = "CatName"
  5. CatID.DataSource=TheResults
  6. CatID.DataBind()
  7. TheSQL.dispose()
  8. TheResults.dispose()
  9. objConn.close()

While the list itself, plus the results table, is generated as follows:
ASP.NET Syntax (Toggle Plain Text)
  1. <form runat="server">
  2. <table border="0" cellpadding="0" cellspacing="5" width="98%" align="center">
  3. <tr>
  4. <td>
  5. <a href="menu.aspx"><img src="images/backbutton.gif" alt="Back" border="0" align="left">Back</a><BR><BR>
  6. </td>
  7. </tr>
  8. <tr>
  9. <td>
  10. <img src="images/contractor.gif" alt="Contractors" align="left">Current Contractors for <%=session("LogInName")%><BR><BR>
  11. <asp:dropdownlist id="CatID" name="CatID" runat="server" />&nbsp;<asp:Button Text="GO" OnClick="Submit" runat="server"/>
  12. </td>
  13. </tr>
  14. <tr>
  15. <td>
  16. <asp:GridView ID="GridViewCompanyMany" runat="server" AutoGenerateColumns="False" DataKeyNames="ContID" DataSourceID="SqlDataSource1" AllowSorting="True" AllowPaging="True" width="100%" borderwidth="1" borderstyle="solid" bordercolor="#CCCCCC">
  17. <HeaderStyle HorizontalAlign="Left" backcolor="#9D9D9D" forecolor="#FFFFFF" />
  18. <Columns>
  19. <asp:HyperLinkField DataNavigateURLFields="ContID" DataNavigateUrlFormatString="contractorview.aspx?ContID={0}" DataTextField="ContName" HeaderText="Contractor" SortExpression="ContSName" />
  20. <asp:BoundField DataField="ContEmail" HeaderText="Email" SortExpression="ContEmail" />
  21. <asp:BoundField DataField="ContAvDate" HeaderText="Date Available" SortExpression="ContAvDate" />
  22. <asp:BoundField DataField="ContLocation" HeaderText="Location" SortExpression="Location" />
  23. </Columns>
  24. <PagerSettings Mode="NumericFirstLast" FirstPageText="First" LastPageText="Last" />
  25. <rowstyle backcolor="#FFFFFF"/>
  26. <alternatingrowstyle backcolor="#CCCCCC"/>
  27. </asp:GridView>
  28. <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)">
  29. <SelectParameters>
  30. <asp:ControlParameter ControlID="CatID" Name="CatID" PropertyName="SelectedValue" Type="Int32" />
  31. </SelectParameters>
  32. </asp:SqlDataSource>
  33. </td>
  34. </tr>
  35. </table>
  36. </form>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Athersgeo is offline Offline
11 posts
since Aug 2005
Aug 27th, 2008
0

Re: Dropdownlist Problems

Try placing the page load code inside the if condition as below:
ASP.NET Syntax (Toggle Plain Text)
  1. If Not (IsPostBack) Then
  2.  
  3. TheSQL = New SqlCommand("Select CatID, CatName from RSG_Category order by CatName", objConn)
  4. TheResults = TheSql.ExecuteReader
  5. CatID.DataValueField = "CatID"
  6. CatID.DataTextField = "CatName"
  7. CatID.DataSource=TheResults
  8. CatID.DataBind()
  9. TheSQL.dispose()
  10. TheResults.dispose()
  11. objConn.close()
  12.  
  13. End If
Last edited by RehanaAmiruddin; Aug 27th, 2008 at 6:45 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RehanaAmiruddin is offline Offline
2 posts
since Aug 2008
Aug 27th, 2008
0

Re: Dropdownlist Problems

Ah! That's got it; thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Athersgeo is offline Offline
11 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Show top readers
Next Thread in ASP.NET Forum Timeline: Datagrid to Datatable





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC