Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding Dropdownlist to Datalist

Status
Not open for further replies.

Pluto87

Programmer
Oct 7, 2011
23
US
Hi there,

I am trying to create a webpage where the user selects a last name from a dropdownlist then the information is display in the datalist. I have done this before (twice) but this time, it's stomping me. There's really no programming involved, just data bounding the fields. But here's my description/problem:

On my page I have a DropDownList, 2 SQLDataSource (SQLDataSource1 & SQLDataSource2), and a DataList.

SQLDataSource1 is connected to one Access databaseconnectionstring where Specify columns from a table or view is selected. Fields LastName and FirstName is selected then order by LastName, FirstName.

SQLDataSource2 is also connected to same Access databaseconnectionstring and Specify columns from a table or view is also selected. Fields LastName, FirstName, Address, City, State, Etc are selected.

The DataList is connected to SQLDataSource2.

My problem is when I add a label to the datalist, and databinding it, it keeps giving me "abc" instead of "databound".

Also, my Dropdownlist is displaying duplicate LastName. I need it to diplay one LastName but when the user chooses a LastName to display, the DataList needs to show if there are more people with the same LastName.

Did I miss something? Thanks in advance for you help!

 
There's really no programming involved, just data bounding the fields.
that is programming, even if you don't explicitly write VB/C# code, code is generated and compiled.
My problem is when I add a label to the datalist, and databinding it, it keeps giving me "abc" instead of "databound".
have you disabled form auto-generation? this might be the problem.
Also, my Dropdownlist is displaying duplicate LastName.
your query should only select distinct values.
Code:
select distinct lastname from table order by lastname
the data source driving the datalist should select records where lastname = selected value.
Code:
select firstname, lastname, ... from table where lastname = @parameter order by firstname

It may also be worth noting some common pitfalls in your scenario.

1. you are not limiting the number of results returned by your queries. this will be a problem if you are returning hundreds or thousands of results. to mitigate this problem you will need to include paging in your queries. Not paging in the datalist, but paging in the query itself.

2. DataSourceControls are the worst part about webforms. i would strongly suggest replacing them with any other data access strategy: raw ado.net, dapper, massive, active record, nh, ef, etc. you have little to no control over datasource controls. you cannot optimize them (other than to replace them) and you cannot step through and debug them.

3. Access was never meant for large scale multiuser environments like the web. using Access may not be a problem for small websites with just a few users, but if you expect any volume of traffic or heavy data crunching, Access may start to fail. there is also the issue of a lack of transaction support in access, but suspect that isn't a concern. otherwise you would have chosen a different RDBMS.


Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Thank you so much, the duplicates aren't showing anymore. Yes, the auto-generation is off. But this: select firstname, lastname, ... from table where lastname = @parameter order by firstname .. isn't working. It is still pull all the data despite selecting any LastName from the dropdownlist.

My work is somewhat outdated. We are still running some data on Access. They aren't large data, but just enough.
 
chances are the bindings between the drop down list, data source 2 and data list aren't configured correctly. or the query isn't properly filtering results.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Thank for your help. Everything is showing up on the datalist, but it is still pulling all the data once I debug the page. I need it to pull data when a user selects a last name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top