473,323 Members | 1,551 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,323 software developers and data experts.

DropDownList selectedIndex is not updated

Hi,

I am trying to read the DropDownList's selectedIndex when it fires the
event
"SelectedIndexChanged", however, the index value is always 0 no matter
what I've clicked. I just wonder what have I done wrong in my code...

This is how I populate my list at the Page_Load!!!!
Dim myCMD As SqlCommand = New SqlCommand(strSQL, cn)
Dim myReader As SqlDataReader = myCMD.ExecuteReader()
Dim fNextResult As Boolean = True

lstEmployee.Items.Clear()
Do Until Not fNextResult
Do While myReader.Read()
If Not myReader.IsDBNull(0) Then
lstEmployee.Items.Add(New
ListItem(myReader.GetString(1), myReader.GetInt32(0)))
End If
Loop
fNextResult = myReader.NextResult()
Loop
myReader.Close()
Thanks in advance. Any help will be greatly appreciated.
Wanda
Nov 18 '05 #1
1 2263
Assume from potential readiability problems with the code, make sure it's
wrapped in an:

If Not Page.IsPostBack Then
... 'put your code in here
end if

Otherwise, on postback, your ddl is repopulated and its selected value lost.

Karl
"Wanda" <wa*****@rogers.com> wrote in message
news:11**************************@posting.google.c om...
Hi,

I am trying to read the DropDownList's selectedIndex when it fires the
event
"SelectedIndexChanged", however, the index value is always 0 no matter
what I've clicked. I just wonder what have I done wrong in my code...

This is how I populate my list at the Page_Load!!!!
Dim myCMD As SqlCommand = New SqlCommand(strSQL, cn)
Dim myReader As SqlDataReader = myCMD.ExecuteReader()
Dim fNextResult As Boolean = True

lstEmployee.Items.Clear()
Do Until Not fNextResult
Do While myReader.Read()
If Not myReader.IsDBNull(0) Then
lstEmployee.Items.Add(New
ListItem(myReader.GetString(1), myReader.GetInt32(0)))
End If
Loop
fNextResult = myReader.NextResult()
Loop
myReader.Close()
Thanks in advance. Any help will be greatly appreciated.
Wanda

Nov 18 '05 #2

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

Similar topics

2
by: rmorvay | last post by:
I am trying to dynamically build a dropdownlist and bind it to a cell in a grid. I tried to utilize the following code but I am stuck at the point where I bind the dropdownlist to the grid cell. ...
2
by: jm | last post by:
I have datagrid. On this datagrid there is a button and a dropdownlist. When I press the button, I want the selectedIndex of the dropdownlist. There is a button and a dropdownlist for each...
2
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
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 =...
2
by: John Blair | last post by:
Hi, I have a dropdownlist in a grid header template - i have autopostback on but when i check the selectedindex in the page_load event (i have a routine which identifies the control that caused...
4
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
1
by: clickon | last post by:
Forget about the controlParameter for the moment, for testing purposes i have created the following Markup: <asp:Table ID="tblSelectRoute" runat="server" CssClass="asp-table"> <asp:TableRow>...
1
by: Jason Wilson | last post by:
I have two dropdownlists that are bound to the same datasource and I have a couple of questions: 1) Because they are bound to the same datasource, I am assuming that they only make 1 round trip...
1
by: pleaseexplaintome | last post by:
Hi all, I have a datagrid with a dropdownlist and would like to have the dropdownlist display a database value correctly while the grid is in edit mode. I have a templatecolumn as follows: ...
1
by: marcbb | last post by:
Hi all, I have a really strange problem working with Dropdownlists in a DataGrid. I'm trying to preselect some values from the DropDownlist for each row in the DataGrid, but it seems that...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.