.NETGURU
Newbie databind dropdownlist question
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.aspnet.webcontrols.

Post a new message to this list...

dw
Hello, all. I'm just starting to work with ASP.NET in VS.NET 2003. I've
created a page with a dropdownlist server control (lstStates) that should
pull in the contents of an Access table tblValidStateAbbr (has states and
their abbreviations). However, no matter what I do, I can't get the dropdown
to show any data on the page.

I have a connection, an OLE DB data adapter, and a dataset that contains the
SELECT to the tblValidStateAbbr. All were created via double-clicking the
data objects on the DATA tab of the Toolbox and following the wizards.

In the pageload event of the code behind file, I have this code. I've been
doing years of ASP development, and ASP.NET is new to me. I think I'm
missing something simple. Any help is appreciated. Thank you.

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Me.OleDbDataAdapter1.Fill(Me.DsStates1)
Me.lstStates.DataBind()

End Sub

Reply to this message...
 
    
Scott M.
Where is the drop down setting its data source?

"dw" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
dw
Scott, I got it! I had set the Data Member property for the drop down in the
Property window to tblValidStateAbbr. Once I cleared that, it worked.
Apparently you can't have both the Data Source and Data Member with values
in them. Thanks for your help.

"Scott M." <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
dw
Scott, I've got another question: How do I use the same data adapter to pull
in another table unrelated to the states table? Thanks.

"dw" <Click here to reveal e-mail address> wrote in message
news:epQv%Click here to reveal e-mail address...
> Scott, I got it! I had set the Data Member property for the drop down in
the
[Original message clipped]

Reply to this message...
 
    
Scott M.
A DataAdapter works based on its Command Objects (Select, Insert, Update &
Delete) that are child objects of the DataAdapter object. If you want to
pull data from a different table in, you'll either have to change the Select
Command of the DataAdapter to a new SQL statement (or stored procedure) and
re-fill your DataSet or use a new DataAdapter.

"dw" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Scott M.
I have found that it is not a good idea to set the DataSource, DataTextField
or DataMember properties using the properties window because they do cause
problems when you want to do something later in code that requires a
different setting for these, so if I am going to create the object using
design techniques, I set these values in code.

"dw" <Click here to reveal e-mail address> wrote in message
news:epQv%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
dw
Thank you, Scott :) Very good information. I appreciate your time on this.

"Scott M." <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> I have found that it is not a good idea to set the DataSource,
DataTextField
[Original message clipped]

Reply to this message...
 
    
Scott M.
No problem. Good luck!

"dw" <Click here to reveal e-mail address> wrote in message
news:%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
dw
Thanks, Scott, for your reply. I set the Data Source of the drop down by
selecting it in Design View and going to the the Property window, and simply
selecting the dsStates1 dataset. That's also where I set the DataTextField
and DataValueField to "state" and "abbr" (without the quotations).

"Scott M." <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Data.Common.DataAdapter
System.Data.DataSet
System.EventArgs




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification