Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals 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
 
Old July 20th, 2010, 06:11 PM
Registered User
 
Join Date: Jul 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using SQLDatasource with Dropdownlist box

Ok, so setting up a dropdownlist box to be populated from a SqlDataSource control is not a big thing - - like so:

<asp: dropdownlist ID="ddlAllegs" RepeatColumns="2" runat="server"
Width="728px" Height="580px" DataSourceID="sdsAllegs"
DataTextField="Allegations" DataValueField="Alleg_ID">
</asp: dropdownlist >

<asp:SqlDataSource ID="sdsAllegs" runat="server"
ConnectionString="<%$ ConnectionStrings:MPEEC %>"
SelectCommand="SELECT[Alleg_ID],[Allegations]FROM [Aux_Allegations_Table]"></asp:SqlDataSource>

BUT now, when I do my Page Load and I want to call sub RetrieveData() where I want to set the dropdown selected item based upon a value retrieved from a table like so :

ddlAllegs.Items.FindByText(myDataReader("Allegatio ns")).Selected = True

BUT - the dropdownlist has not been loaded yet and the application throws and error. Hate to give up my new found favorite control, SqlDataSource, and be forced to go back to the old fashion way of manually populating.
Any Ideas?
 
Old July 21st, 2010, 04:32 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can write your code in the DataBound event of the control, or call MyDropDownList.DataBind() to force it to databind first.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 22nd, 2010, 01:17 AM
Registered User
 
Join Date: Jul 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default That worked

Iram

Thanks! That worked and so simple! I have so much to learn. Thanks for the help

Tom





Similar Threads
Thread Thread Starter Forum Replies Last Post
sqldatasource imjayakumar ASP.NET 2.0 Professional 3 May 21st, 2007 01:56 PM
sqldatasource imjayakumar Crystal Reports 0 May 19th, 2007 03:12 AM
Dropdownlist box arnniema Classic ASP Basics 1 November 14th, 2005 06:13 PM
SQLDataSource bmains ASP.NET 2.0 Basics 1 December 19th, 2004 09:12 AM
Need help with XML and DropDownList box waru BOOK: Beginning ASP.NET 1.0 2 May 27th, 2004 06:23 PM





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