Dropdownlist Problems

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2005
Posts: 11
Reputation: Athersgeo is an unknown quantity at this point 
Solved Threads: 0
Athersgeo Athersgeo is offline Offline
Newbie Poster

Dropdownlist Problems

 
0
  #1
Aug 27th, 2008
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:
  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:
  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>
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 2
Reputation: RehanaAmiruddin is an unknown quantity at this point 
Solved Threads: 0
RehanaAmiruddin RehanaAmiruddin is offline Offline
Newbie Poster

Re: Dropdownlist Problems

 
0
  #2
Aug 27th, 2008
Try placing the page load code inside the if condition as below:
  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 11
Reputation: Athersgeo is an unknown quantity at this point 
Solved Threads: 0
Athersgeo Athersgeo is offline Offline
Newbie Poster

Re: Dropdownlist Problems

 
0
  #3
Aug 27th, 2008
Ah! That's got it; thanks.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC