3 Replies - 257 Views - Last Post: 25 April 2019 - 03:42 AM Rate Topic: -----

#1 choudhmh   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-April 19

Dropdown list reverts to value 0

Posted 25 April 2019 - 03:11 AM

I've got a dropdown list which populates another dropdown list (2nd one). I have a button click which supposed to take information from the 2nd populated list and do basic calculation.
Problem is when i click the button the 2nd dropdownlist goes back to deafult value (0) - does not stay on the one i've selected. Tried looking over the internet for a solution can't seem to figure out why this is happening.

Anyone with any information will appreciate the feedback

Private Sub From_Load(sender As Object, e As EventArgs) Handles From.Load
        Rate.Items.Clear()
        Dim value = From.SelectedValue
        Rate.Items.Add(New ListItem("Please Select...", 0))
        If value = 1 Then
            Rate.Items.Add(New ListItem("USD", 1))
            Rate.Items.Add(New ListItem("Euro", 2))
            Rate.DataBind()
        End If

    End Sub

    Private Sub Convert_Load(sender As Object, e As EventArgs) Handles Convert.Load
        If Rate.SelectedValue = 1 Then
            Total.Text = (Val(Amount.Text) * 1.5)
        End If
    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Dropdown list reverts to value 0

#2 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,050
  • Joined: 12-December 12

Re: Dropdown list reverts to value 0

Posted 25 April 2019 - 03:23 AM

From_Load Is the above an extract of your real code? Please just copy and paste the relevant parts of the original code.

If you are repopulating a drop-down list then I doubt it will retain the previous selection. You will need to note (store) the selected item/index and reinstate it.
Was This Post Helpful? 0
  • +
  • -

#3 choudhmh   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-April 19

Re: Dropdown list reverts to value 0

Posted 25 April 2019 - 03:35 AM

View Postandrewsw, on 25 April 2019 - 03:23 AM, said:

From_Load Is the above an extract of your real code? Please just copy and paste the relevant parts of the original code.

If you are repopulating a drop-down list then I doubt it will retain the previous selection. You will need to note (store) the selected item/index and reinstate it.


Yes that's the exact copy of the original code. The front part is here:
asp:DropDownList ID="From" runat="server" AutoPostBack="true">
                <asp:ListItem Value="0">Select....()</asp:ListItem>
               <asp:ListItem Value="1">GBP()</asp:ListItem>
                <asp:ListItem Value="2">USD($)</asp:ListItem>
                <asp:ListItem Value="3">Euro</asp:ListItem>

            </asp:DropDownList>
            <br />
            
            <asp:DropDownList ID="Rate" runat="server">
            </asp:DropDownList>


So you're saying i need to store the value somewhere then use the value from the stored information?
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,050
  • Joined: 12-December 12

Re: Dropdown list reverts to value 0

Posted 25 April 2019 - 03:42 AM

I thought this was about WinForms; I have moved it to the ASP.NET forum.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1