selected item won't change

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TJS

    selected item won't change

    can someone tell me why the selected item won't reflect user change in this
    little droplist example



    <%@ Page Language="VB" %>
    <script runat="server">

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    mydropdown.Item s.clear
    mydropdown.Item s.Add( New ListItem( "alpha", "alpha" ))
    mydropdown.Item s.Add( New ListItem( "beta", "beta" ))
    mydropdown.Item s.Add( New ListItem( "gamma", "gamma" ))

    End Sub


    Sub Select_Click(By Val sender As Object, ByVal e As EventArgs)

    Messagex.text &= " selected = "
    Messagex.text &= mydropdown.Sele ctedIndex

    End Sub

    </script>
    <html>
    <head>
    </head>
    <body>
    <form runat="server">

    <table cellspacing="0" cellpadding="0" width="50%" border="0">
    <tbody>
    <tr valign="center" >
    <td align="left" width="100%">
    <span>Select&nb sp;:</span>
    </td>
    <td align="left" width="100%">
    <asp:DropDownLi st id="mydropdown " runat="server"
    enableviewstate ="true"></asp:DropDownLis t>
    </td>
    <td align="left" width="100%">
    <asp:Button id="btnSelect" onclick="Select _Click"
    runat="server" CausesValidatio n="False" Text="GO"></asp:Button>
    </td>
    </tr>
    <tr valign="center" >
    <td align="left" width="100%">
    <br />
    <asp:Label id="Messagex" runat="server"
    enableviewstate ="true" forecolor="red" width="80%"></asp:Label></td>
    </tr>
    </tbody>
    </table>
    </form>

    </body>
    </html>



  • Karl

    #2
    Re: selected item won't change

    when the user clicks the button, Page_Load fires first, thus clearing the
    dropdownlist and re-adding the listitems...

    If Not PAge.IsPostBack then
    mydropdown.Item s.Add( New ListItem( "alpha", "alpha" ))
    mydropdown.Item s.Add( New ListItem( "beta", "beta" ))
    mydropdown.Item s.Add( New ListItem( "gamma", "gamma" ))
    end if

    Karl

    "TJS" <nospam@here.co m> wrote in message
    news:eDItfbrjEH A.3536@TK2MSFTN GP12.phx.gbl...[color=blue]
    > can someone tell me why the selected item won't reflect user change in[/color]
    this[color=blue]
    > little droplist example
    >
    >
    >
    > <%@ Page Language="VB" %>
    > <script runat="server">
    >
    > Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    >
    > mydropdown.Item s.clear
    > mydropdown.Item s.Add( New ListItem( "alpha", "alpha" ))
    > mydropdown.Item s.Add( New ListItem( "beta", "beta" ))
    > mydropdown.Item s.Add( New ListItem( "gamma", "gamma" ))
    >
    > End Sub
    >
    >
    > Sub Select_Click(By Val sender As Object, ByVal e As EventArgs)
    >
    > Messagex.text &= " selected = "
    > Messagex.text &= mydropdown.Sele ctedIndex
    >
    > End Sub
    >
    > </script>
    > <html>
    > <head>
    > </head>
    > <body>
    > <form runat="server">
    >
    > <table cellspacing="0" cellpadding="0" width="50%" border="0">
    > <tbody>
    > <tr valign="center" >
    > <td align="left" width="100%">
    > <span>Select&nb sp;:</span>
    > </td>
    > <td align="left" width="100%">
    > <asp:DropDownLi st id="mydropdown " runat="server"
    > enableviewstate ="true"></asp:DropDownLis t>
    > </td>
    > <td align="left" width="100%">
    > <asp:Button id="btnSelect" onclick="Select _Click"
    > runat="server" CausesValidatio n="False" Text="GO"></asp:Button>
    > </td>
    > </tr>
    > <tr valign="center" >
    > <td align="left" width="100%">
    > <br />
    > <asp:Label id="Messagex" runat="server"
    > enableviewstate ="true" forecolor="red" width="80%"></asp:Label></td>
    > </tr>
    > </tbody>
    > </table>
    > </form>
    >
    > </body>
    > </html>
    >
    >
    >[/color]


    Comment

    Working...