473,320 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

selected item won't change

TJS
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.Items.clear
mydropdown.Items.Add( New ListItem( "alpha", "alpha" ))
mydropdown.Items.Add( New ListItem( "beta", "beta" ))
mydropdown.Items.Add( New ListItem( "gamma", "gamma" ))

End Sub
Sub Select_Click(ByVal sender As Object, ByVal e As EventArgs)

Messagex.text &= " selected = "
Messagex.text &= mydropdown.SelectedIndex

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&nbsp;:</span>
</td>
<td align="left" width="100%">
<asp:DropDownList id="mydropdown" runat="server"
enableviewstate="true"></asp:DropDownList>
</td>
<td align="left" width="100%">
<asp:Button id="btnSelect" onclick="Select_Click"
runat="server" CausesValidation="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>

Nov 18 '05 #1
1 1749
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.Items.Add( New ListItem( "alpha", "alpha" ))
mydropdown.Items.Add( New ListItem( "beta", "beta" ))
mydropdown.Items.Add( New ListItem( "gamma", "gamma" ))
end if

Karl

"TJS" <no****@here.com> wrote in message
news:eD**************@TK2MSFTNGP12.phx.gbl...
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.Items.clear
mydropdown.Items.Add( New ListItem( "alpha", "alpha" ))
mydropdown.Items.Add( New ListItem( "beta", "beta" ))
mydropdown.Items.Add( New ListItem( "gamma", "gamma" ))

End Sub
Sub Select_Click(ByVal sender As Object, ByVal e As EventArgs)

Messagex.text &= " selected = "
Messagex.text &= mydropdown.SelectedIndex

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&nbsp;:</span>
</td>
<td align="left" width="100%">
<asp:DropDownList id="mydropdown" runat="server"
enableviewstate="true"></asp:DropDownList>
</td>
<td align="left" width="100%">
<asp:Button id="btnSelect" onclick="Select_Click"
runat="server" CausesValidation="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>

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Aaron Prohaska | last post by:
I'm having the problem with this drop down list on postback. For some reason both the ListItems get selected when I change the selected item. Using the code below I'm building the drop down list in...
10
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
1
by: Karen Grube | last post by:
Hi! I'm using a standard server side ASP.Net listbox control on a web form. The page is basically various shades of green. The listbox itself has a pale green background and forest green text...
2
by: Brian Henry | last post by:
say I have a databound combo box, which allows for text entry still (DropDownStype = DropDown in this case). now, If the user doesn't enter manually an item in the data bound list, nothing...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
3
by: Iain | last post by:
Hi All I have 2 DropDownList boxes on a page. The first (id= "Operation") is populated on PageLoad with the contents of a database table. The second id="WorkStations" will not be populated...
3
by: peter.mosley | last post by:
I've tried googling for the answer to this problem, without any luck. I'm sure the truth must be out there somewhere! I have a multiselect listbox populated with many items (set by the RowSource...
0
by: Geary | last post by:
I have a drop down list on an asp.net 2 page that is bound to a table. By default it displays the first item as the selected item. But I want to make sure that the user must change the selection. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.