473,788 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList always returning the first item

Hi,
weird problem I'm having cant seem to figure out what is going on.

I have a dropdownlist that gets populated from db and a button that causes
a post back
when I assign the value of the dropdownlist to a string var it always
returns the first item regardless of what was selected

code is simple

in the button click event

string name = ddlName.Selecte dItem.ToString( );

I'm learning asp.net and this is my first project so excuse the newbie
question .

Nov 19 '05 #1
3 4202
Did you try “name = ddlName.Selecte dItem.Value”.
ToString() is probably not the selected ListItem value.

Shaw
"Siamak Zahedi" wrote:
Hi,
weird problem I'm having cant seem to figure out what is going on.

I have a dropdownlist that gets populated from db and a button that causes
a post back
when I assign the value of the dropdownlist to a string var it always
returns the first item regardless of what was selected

code is simple

in the button click event

string name = ddlName.Selecte dItem.ToString( );

I'm learning asp.net and this is my first project so excuse the newbie
question .

Nov 19 '05 #2
yes things ive tryed so far:

string name = ddlSelectedItem .Value;
string name = ddlSelectedItem .Text;

the first one returns the SelectedValue of the first item in the list
and the Text returns the same as the ToString i had before

im starting to think its maybe because i have it placed in a panel which is
also inside a Main panel
page has a main panel that is visible and a second panel that is not visible
if the user clicks the post back button on the main panel and all the
procedures run with out error the second panels is set to visible and page
is rendered.

on the second panel i have a databound dropdown (one that is causeing the
problem) a html File input set to run on server and a Upload button that
posts back the file selected, the purpose of the drop down is to choose the
directory where the file is saved in...
"Shaw" <Sh**@discussio ns.microsoft.co m> wrote in message
news:DF******** *************** ***********@mic rosoft.com...
Did you try "name = ddlName.Selecte dItem.Value".
ToString() is probably not the selected ListItem value.

Shaw
"Siamak Zahedi" wrote:
Hi,
weird problem I'm having cant seem to figure out what is going on.

I have a dropdownlist that gets populated from db and a button that
causes
a post back
when I assign the value of the dropdownlist to a string var it always
returns the first item regardless of what was selected

code is simple

in the button click event

string name = ddlName.Selecte dItem.ToString( );

I'm learning asp.net and this is my first project so excuse the newbie
question .

Nov 19 '05 #3
Siamak:
Just a guess, but are you rebinding on PostBack? If so you could be
overwriting the selection made by the user. Make sure to wrap the binding
code inside of an

if (!Page.IsPostBa ck){
ddlName.DataSou rce = xxx;
ddlName.DataBin d();
}

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Siamak Zahedi" <T_*@telus.ne t> wrote in message
news:4TeKd.5278 8$Qb.23905@edtn ps89...
Hi,
weird problem I'm having cant seem to figure out what is going on.

I have a dropdownlist that gets populated from db and a button that causes a post back
when I assign the value of the dropdownlist to a string var it always
returns the first item regardless of what was selected

code is simple

in the button click event

string name = ddlName.Selecte dItem.ToString( );

I'm learning asp.net and this is my first project so excuse the newbie
question .

Nov 19 '05 #4

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

Similar topics

3
1835
by: Vinay | last post by:
Hi All: I'm having a strange problem with the dropdownlist. Here is what is happening: I have a webform on which I have a whole bunch of controls. The form has 2 dropdownlists. The dropdowns are bound. The items are loaded just fine into the dropdown lists at the time of page load. When I try to select an item from the dropdown list, it always ends up selecting the first item.
1
1856
by: Null | last post by:
Hello -- Is there a way to prevent the autopostback of a drop down list if there is a "default" item in the list -- example, a drop down list where the first item says "Select One" and the remaining items are all values available for selection....if the user changes the selection I want to postback, unless they are selecting the default item. Is there a way to do this using autopostback? Or should I just use client side script and...
1
2921
by: Timo | last post by:
I am trying to use the DropDownList_SelectedIndexChanged event on a dropdown which is dynamically populated with different values at runtime, depending on what the user has been doing. The dropdown works and the event fires except when the user selects the *first* item in the list, which appears to be the default selection, even though the generated HTML code does not have a "selected" property set. Is it possible to cause the...
5
9905
by: glenn | last post by:
Hi folks, If I want to select the first item in a DropDownList, I need to first select any item other than the first item and then next I select the first item which will then fire an event saying that I clicked the first item. Why can't I just select the first item to get an event to fire without having to first select any other item. Thanks for any tips.
0
1349
by: Ryan Liu | last post by:
In a listview, I found it is pretty nice I can type a letter or more letter quickly to select the NEXT item which begin with that letter(s). But seems the first row, even not high lighted, always been select by default. So when I click the first items' first letter, it goes to next item starts with same letter. For example, I have
2
1857
by: JamesW | last post by:
Hi there. Vstudio 2003, IE 6.0 I have an asp connected to an Access database. A DropDownList on the page shows names from the Db. When the user selects a name from the DropDownList I want the selected name to appear in a text box on the page.
2
6279
by: Tommy Hayes | last post by:
Hello all, I have the following code snippet in my Access app: Dim dbQueryDef As QueryDef Set dbQueryDef = CurrentDb.QueryDefs("QUERY_NAME") ' (1) Set dbQueryDef = CurrentDb.QueryDefs(26) ' (2) Line (1) does not do as I expect it - it always returns the first
5
10704
by: ray | last post by:
A container object provides a method that returns an iterator object. I need to iterate the sequence with that iterator, but need to skip the first item. I can only iterate the whole sequence with: for x in container.iterChildren(): How to skip the first item? It seems that it's a simple question. Could somebody help me? Thanks.
0
1460
by: Vincent | last post by:
I answered my own question. Here's what I did to solve this: 1. Deleted the "selected value="<%# bind("driver") %>" from the dropdownlist. (i did not have this code in my above posting) 2. Placed "Imports System.Data" at the top of my code page to accomodate for the "DataRowView" 3. Entered the following code in my dropdownlist_databound. I got this code from teh following website: ...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10366
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10173
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.