Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 20th, 2008, 11:28 AM
Authorized User
Points: 136, Level: 2
Points: 136, Level: 2 Points: 136, Level: 2 Points: 136, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2006
Location: London Town, , United Kingdom.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default DropDownList, DataSource and Selected Items

Hi,

If I have a SQL DataSource as the data source for a DroDownList [as below], and within this page I have called a record from the DB that relates to this drop down list [but only one value] how do I ensure that /that/ value is selected?

##################### CODE #####################

<asp:DropDownList ID="ddlTowns"
    runat="server"
    DataSourceID="dataTowns"
    DataTextField="GT_Name"
    DataValueField="GT_ID">
</asp:DropDownList>

<asp:SqlDataSource ID="dataTowns"
    runat="server"
    ConnectionString="<%$ ConnectionStrings:dbConn %>"
    SelectCommand="townsSelect"
    SelectCommandType="StoredProcedure">
</asp:SqlDataSource>

##################### END OF CODE #####################

I'm guessing I have to write some code in the aspx.cs file such as

##################### ASPX.CS #####################

protected void Page_Load(object sender, EventArgs e)
    {
        this.ddlTowns.SelectedIndex = ...
    }

##################### END OF ASPX.CS #####################

Any help greatly appreciated..

Can anyone point me in the direction of a great resource for this sort of thing?

Cheers..

Hasta Luego..
KingRoon

DogFightClothing. No dogs. No fighting.
http://www.dogfightclothing.com
__________________
Hasta Luego..
KingRoon

DogFightClothing. No dogs. No fighting.
http://www.dogfightclothing.com
  #2 (permalink)  
Old February 22nd, 2008, 11:08 PM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

I believe you're doing everything correctly. All you need to do is reference the single value you're pulling. Is it the Stored Procedure doing that? or is it in a form control. That's what's going onto the other side of your expression in the .cs file. How are you getting that value?

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
  #3 (permalink)  
Old February 25th, 2008, 10:41 AM
Authorized User
Points: 136, Level: 2
Points: 136, Level: 2 Points: 136, Level: 2 Points: 136, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2006
Location: London Town, , United Kingdom.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, yeah I know /what/ I have to do I think, I just don't know the syntax! :oS

How do I reference the Data from the DataSource in the .aspx.cs page? If the logic is that I want the townID from dataTowns i.e. in this bit:

this.ddlTowns.SelectedIndex = ...

Hasta Luego..
KingRoon

DogFightClothing. No dogs. No fighting.
http://www.dogfightclothing.com


Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of selected items in a listbox sarah lee ASP.NET 2.0 Basics 2 May 17th, 2007 12:20 PM
Cannot have multiple items selected in a DropDownL Ron Howerton ASP.NET 1.0 and 1.1 Basics 23 November 8th, 2006 04:29 PM
Dropdownlist datasource jilly ASP.NET 1.0 and 1.1 Basics 1 October 22nd, 2006 10:16 AM
Cannot have multiple items selected in a DropDownL Ron Howerton ASP.NET 2.0 Basics 2 May 18th, 2006 04:59 AM
selected items in asp:ListBox jtyson Classic ASP Basics 2 July 2nd, 2004 12:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.