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

dropDownList always returns 0 for selected index

if i manually populate a dropDownList, post the page, and then fetch the
selected index, i'm able to get values other than 0. however, when i bound
my dropDownList to a dataReader object, even thought he dropDown's text and
values are showing the dataReader's data fine, i can never return a
selectedIndex other than 0.

lstCompanies.DataSource = oDataReader

lstCompanies.DataTextField = "companyName"

lstCompanies.DataValueField = "id"

lstCompanies.DataBind()

any ideas why?

tks
Nov 19 '05 #1
3 8024
Where has this code been placed - in the Page_Load event? And is it
inside a IsPostBack check.

If Not Page.IsPostBack Then
'databinding goes here
End If

Nov 19 '05 #2
have you forgotten the IsPostBack check ?

the code should look like

if(!Page.IsPostBack())
{
// code to databind lstCompanies...
}

"Dica" wrote:
if i manually populate a dropDownList, post the page, and then fetch the
selected index, i'm able to get values other than 0. however, when i bound
my dropDownList to a dataReader object, even thought he dropDown's text and
values are showing the dataReader's data fine, i can never return a
selectedIndex other than 0.

lstCompanies.DataSource = oDataReader

lstCompanies.DataTextField = "companyName"

lstCompanies.DataValueField = "id"

lstCompanies.DataBind()

any ideas why?

tks

Nov 19 '05 #3

"Sreejith Ram" <Sr*********@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
have you forgotten the IsPostBack check ?
yes, you're both right. adding a isPostBack() fixed everyting.

many tks to both.


the code should look like

if(!Page.IsPostBack())
{
// code to databind lstCompanies...
}

"Dica" wrote:
if i manually populate a dropDownList, post the page, and then fetch the
selected index, i'm able to get values other than 0. however, when i bound my dropDownList to a dataReader object, even thought he dropDown's text and values are showing the dataReader's data fine, i can never return a
selectedIndex other than 0.

lstCompanies.DataSource = oDataReader

lstCompanies.DataTextField = "companyName"

lstCompanies.DataValueField = "id"

lstCompanies.DataBind()

any ideas why?

tks

Nov 19 '05 #4

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

Similar topics

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 =...
3
by: Olivier Verdin | last post by:
Hi, I have a page with several Textboxes and several DropDownList. When I click on a 'save' button, it creates a record in a database. The page works fine under Internet Explorer. It does...
4
by: wolfgang wagner | last post by:
hi all! after successfully integrating a dropdownlist in my datagrid i have another problem: i cannot set the selected index of the dropdownlistbox. here is my code: hardware.aspx...
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,...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
2
by: jnoody | last post by:
The problem I am having is with the SelectedIndexChanged event not always firing or the SelectedIndex property not being correct when the event does fire. The code is below, but here are some...
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...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.