Page Post Back -- how to retain selecteditem.value of TWO dropdowns???

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Page Post Back -- how to retain selecteditem.value of TWO dropdowns???

    Hi,

    On Page Load (if not postback), the user selects a choice from
    dropdownlist1.

    On SelectedItemChanged for dropdownlist1, dropdownlist2 is populated
    and the user selects an item.

    I cannot find a combination where I can RETAIN both values during
    postback...if I put if not posback on the change event of
    dropdownlist1, it doesn't populate #2...

    Any help appreciated!

    Kathy
    KathyB Guest

  2. Similar Questions and Discussions

    1. How to Post back page from Client side code?
      Hi, I am developing a website in ASP.NET. I want to have a client side code to confirm the deletion of some information from backend database. I...
    2. post the result back to same page??
      <html> <body> <Form action="calc.asp" method="post" name="calc"> <P>NUM1: <input type="text" name="num1"> <P>NUM2: <input type="text"...
    3. Form Retain Info on Back?
      Hi All, I have a php form that I run a test to see if they have entered in all required fields before inserting into a MySQL db. The PHP script...
    4. [PHP] Form Retain Info on Back?
      Is there a simple way of retaining this information so the user doesn't has to retype all the information in? The answer is in the archives...
    5. Post back
      hello all, I have a simple question. on my .aspx page I have bunch of textbox, and dropdowns. One of the dropdown2 has postback = true. When the...
  3. #2

    Default Re: Page Post Back -- how to retain selecteditem.value of TWO dropdowns???

    What does your event handler for SelectedItemChanged for dropdownlist1 look
    like?

    Todd Thompson
    Todd Thompson Guest

  4. #3

    Default Re: Page Post Back -- how to retain selecteditem.value of TWO dropdowns???

    Here are both pageload and selecteditemchanged...when I load the page,
    it let's me select the Customer (control 1), and DOES filter the second
    control, but at the same time, resets control 1 to "Select
    Customer"...ugh.

    Both controls set to autopostback and enable viewstate.

    Any ideas?

    Thanks.
    KathyBurke

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here

    If Not IsPostBack Then
    Dim Conn1 As OleDbConnection
    Dim Rdr1 As OleDbDataReader
    Dim Cmd1 As OleDbCommand
    Dim strSQL As String
    Conn1 = New OleDbConnection(strConn)
    strSQL = "SELECT DISTINCT Customer FROM tblCustomers ORDER
    BY Customer"
    Cmd1 = New OleDbCommand(strSQL, Conn1)
    Conn1.Open()
    Rdr1 = Cmd1.ExecuteReader()
    cboCust.DataSource = Rdr1
    cboCust.DataBind()
    cboCust.Items.Insert(0, "Select Customer")
    cboCust.SelectedIndex = 0
    Rdr1.Close()
    Conn1.Close()
    End If

    End Sub

    Private Sub cboCust_SelectedIndexChanged(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    cboCust.SelectedIndexChanged

    Dim Conn2 As New OleDbConnection()
    Dim Rdr2 As OleDbDataReader
    Dim strSQL2 As String = "SELECT Assy FROM tblAssy WHERE
    ([Customer] = @customer) ORDER BY Assy"
    Dim Cmd2 As New OleDbCommand(strSQL2, Conn2)
    Conn2 = New OleDbConnection(strConn)
    Dim prmCustomer As OleDbParameter = New
    OleDbParameter("@customer", OleDbType.VarChar, 50)
    prmCustomer.Value = cboCust.SelectedItem.Value
    Cmd2.Parameters.Add(prmCustomer)
    Cmd2.Connection = Conn2
    Conn2.Open()
    Rdr2 = Cmd2.ExecuteReader()
    cboAssy.DataSource = Rdr2
    cboAssy.DataBind()
    cboAssy.Items.Insert(0, "Select Assembly")
    cboCust.SelectedIndex = 0
    Rdr2.Close()
    Conn2.Close()
    End Sub


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Kathy Burke Guest

  5. #4

    Default Re: Page Post Back -- how to retain selecteditem.value of TWO dropdowns???

    In your handler you have the following line:


    On 27-Jun-2003, Kathy Burke <anonymous@devdex.com> wrote:
    > cboCust.SelectedIndex = 0

    If I'm understanding your code and problem correctly, you are setting the
    index of the drop down to the first item instead of leaving it set to its
    previous value.


    Todd Thompson
    Todd Thompson Guest

  6. #5

    Default Re: Page Post Back -- how to retain selecteditem.value of TWO dropdowns???

    You are correct in that the code contained within the Page_Load function and
    in the IF NOT POSTBACK conditional won't be run.

    But in your event handler cboCust_SelectedIndexChanged, you are setting the
    cboCust.SelectedIndex=0 which will affect that drop down on the current
    page.

    Todd Thompson
    Todd Thompson Guest

  7. #6

    Default Re: Page Post Back -- how to retain selecteditem.value of TWO dropdowns???

    Todd,

    I'm an idiot...I copied the code for cboAssy but forgot to change that
    control ref...THANK YOU...

    KathyBurke

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Kathy Burke Guest

  8. #7

    Default Re: Page Post Back -- how to retain selecteditem.value of TWO dropdowns???

    Kathy,

    No problem, I've done the same thing myself.

    Glad to be of help.

    Todd
    Todd Thompson Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139