Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Get Value From Something Other Than The Index In DropDownList

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cindy - 29 Aug 2007 09:19 GMT
Hi.

Say a the query behind a dropdown list lists various fields -- i.e.,
ID, State, City.  The dropdownlist will display the state and store
the ID.  How do I retrieve the associated city?

Thanks!

Cindy
Eliyahu Goldin - 29 Aug 2007 09:49 GMT
Your query will result in populating some object  (data source) with data
and the ddl will databind to that object. You will need to persist the data
source between postbacks. You can do it in a session variable. Or you may
choose running the query on every postback to re-populate the data source.
Once you know the selected id, you can search your data source to locate the
data item and get the city from the data item.

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

> Hi.
>
[quoted text clipped - 5 lines]
>
> Cindy
Cindy - 29 Aug 2007 09:57 GMT
Hey.  Do you have an example of this?  All I wanted was to be able to
say, whatever=dropdownlist.column(2) and it returns the information.
Simple.  I do not have enough experience to understand everything you
just wrote.

Thanks!

Cindy

On Aug 29, 10:49 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.org> wrote:
> Your query will result in populating some object  (data source) with data
> and the ddl will databind to that object. You will need to persist the data
[quoted text clipped - 19 lines]
>
> - Show quoted text -
Mark Rae [MVP] - 29 Aug 2007 09:53 GMT
> Say a the query behind a dropdown list lists various fields -- i.e.,
> ID, State, City.  The dropdownlist will display the state and store
> the ID.  How do I retrieve the associated city?

Several ways...

1) Unless your DataSet is quite large, you can store it in a client-side
JavaScript array - this would allow you to retrieve the associated city
client-side without any postback / callback...

2) Concatenate the ID and city with a separator charactor and use that as
the value of the dropdown e.g.

   1¬London
   2¬Paris
   3¬New York

Then, when you need to, you can simply split the value on your character
separator e.g.

MyDropDown.SelectedValue.Split('¬')[1];

3) Use AJAX to either look the data up from the database as and when
required or, (maybe) more efficiently, persist the data in Session or
Application cache if it's unlikely to change very often...

I'd go for the third option, personally...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Cindy - 29 Aug 2007 09:59 GMT
> > Say a the query behind a dropdown list lists various fields -- i.e.,
> > ID, State, City.  The dropdownlist will display the state and store
[quoted text clipped - 27 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net

Thanks!  The splitting ought to do it!
Alexey Smirnov - 29 Aug 2007 09:58 GMT
> Hi.
>
[quoted text clipped - 5 lines]
>
> Cindy

string stateid = StateList.SelectedItem.Value;
string sql = "SELECT cityid, city FROM cities WHERE stateid='" +
stateid + "'";

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.