Send DropDownList Selected Item Value to another Page using Session in ASP.Net

Last Reply on Dec 07, 2012 01:59 AM By RkHirpara

Posted on Dec 07, 2012 12:14 AM

hi i am facing a problem in my code..i have one drop downlist in my page,i store the values in session ,whenever i select the name of the dropdownlist it will redirect to another page,if i select the firstvalue of the dropdownlist,it redirect to another page,and retrive the session value,in that session value i have a case in my page load,if it is firstvalue of the dropdownlist is selected it will call case 1 and executes,if the second value of the dropdownlist is selected,it will call case 2 and it executes ,its not working properly for me..here is my code

dropdownlist.aspx.vb

 Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        If DropDownList1.SelectedItem.Value = "" Then
            ClientScript.RegisterStartupScript(Page.[GetType](), "no selection", "<script language='javascript'>alert('Please Select One Company')</script>")
        ElseIf DropDownList1.Text = "company1" Then
            Response.Redirect("default.aspx")
            Session("1") = DropDownList1.SelectedItem.Value
        ElseIf DropDownList1.Text = "company2" Then
            Response.Redirect("default.aspx")
            Session("2") = DropDownList1.SelectedItem.Value
        ElseIf DropDownList1.Text = "company3" Then
            Response.Redirect("default.aspx")
            Session("3") = DropDownList1.SelectedItem.Value
        End If
    End Sub

default.vb


 in page load

 Label39.Text = Session("1")
        Label39.Text = Session("2")
        Label39.Text = Session("3")
                connection.ConnectionString = ("Data Source=RIFAYEE-PC;Initial Catalog=HR;Integrated Security=True;Pooling=False")
         Dim a As String
        Dim count As Integer
         a = Label39.Text
          Select Case a
         Case 1
          cmd = New SqlCommand("select count(*)from company1", connection)
          connection.Open()
          count = Convert.ToInt16(cmd.ExecuteScalar()) + 1
          txtempid.Text = "OPA" & count
          connection.Close()
          txtfname.Focus()
            Case 2
         cmd = New SqlCommand("select count(*)from company2", connection)
        connection.Open()
         count = Convert.ToInt16(cmd.ExecuteScalar()) + 1
         txtempid.Text = "OPL" & count
         connection.Close()
         txtfname.Focus()
           Case 3
         cmd = New SqlCommand("select count(*)from company3", connection)
          connection.Open()
          count = Convert.ToInt16(cmd.ExecuteScalar()) + 1
          txtempid.Text = "OPM" & count
          connection.Close()
          txtfname.Focus()
         End Select
pls help me

 

Posted on Dec 07, 2012 01:59 AM

Hi rifayeem please tell me what is the unexpected behaviour you are facing ?

Other thing I foung in your code is that the session will not set as you wrote the code after redirection. The code should be like.

 

Session("1") = DropDownList1.SelectedItem.Value
Response.Redirect("default.aspx")

First set the session and then redirect and check your Issue is solved..!!! and not please clarify me what issue you are facing.