Results 1 to 2 of 2

Thread: Help with Postback issue on Drop Down Lists

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    2

    Help with Postback issue on Drop Down Lists

    Hi, can someone help me with a postback issue on the following code. I basically have 2 dropdown lists, and i want to pass the selections on a querystring to another page. However, and I'm not using postback, and the values that get sent are always the first ones, regardless of what you select. I'm a real beginner, can someone please just show me how to fix this, I'm pulling my hair out.

    Code:
    <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" EnableViewState="false" %>
         <%@ Import Namespace="System.Data.OleDb" %>
         <script runat="server" language="VB">
     Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;" & "Data Source=C:\Clients\NYCF\website\database\nycf.mdb")
         	Dim objCmd As OleDbCommand
         	Dim objRdr As OleDbDataReader
         
         Sub Page_Load()	
         	objConn.Open()
         
         	objCmd = New OleDbCommand("SELECT Specialty FROM tblSpecialty ORDER BY Specialty",objConn)
         	objRdr = ObjCmd.ExecuteReader()
         	ddlSpecialty.Datasource = objRdr
         	ddlSpecialty.DataValueField = "Specialty"
         	ddlSpecialty.DataTextField = "Specialty"
         	ddlSpecialty.DataBind()
         	ddlSpecialty.Items.Insert(0, new ListItem("- Please Select -"))
         	objRdr.Close()
         	
         	objCmd = New OleDbCommand("SELECT DISTINCT City FROM tblDoctors ORDER BY City",objConn)
         	objRdr = ObjCmd.ExecuteReader()
         	ddlCity.Datasource = objRdr
         	ddlCity.DataValueField = "City"
         	ddlCity.DataTextField = "City"
         	ddlCity.DataBind()
         	ddlCity.Items.Insert(0, new ListItem("- Please Select -"))
         	objRdr.Close()
         	
         	ObjConn.Close()	
         End Sub
         
         Sub searchSubmit(s As Object, e As ImageClickEventArgs)
     	 Dim strQueryStr As String = "?City=" & Server.UrlEncode(ddlCity.SelectedItem.Text) & "&Specialty=" & Server.UrlEncode(ddlSpecialty.SelectedItem.Text)
         	 Response.Redirect("search_results.aspx" & strQueryStr)
          End Sub
         </script>
         <html>
         <body>
         <form runat="server">
         <asp:DropDownList id="ddlSpecialty" runat="server">
         <asp:DropDownList id="ddlCity" runat="server">
     <asp:ImageButton id="btnSubmit" runat="server" AlternateText="Locate a Doc Now!" ImageUrl="images/button_search_submit.gif" OnClick="searchSubmit" />
         </form>
         </body>
         </html>

  2. #2

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    2

    Re: Help with Postback issue on Drop Down Lists

    Fixed it,! Yay - Apparantly, i needed the viewstate to be on for this to work ( I had this line at the top of the page: EnableViewState="false" )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width