473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Populating a drop downlist

The method below belongs to a class. The method accepts a
dropdownlist as a parameter. Is there any disadvantage to passing in
the control and having this method populate it as opposed to passing
back a datareader from this method and having the webform populate it?

It seems to work great! Just wondering if there may be a disadvantage
to passing a control.

Oh yea, by the way, it is just passing a pointer to the control,
right? Or should I designate that the parameter as a reference value?

public void getStates(System.Web.UI.WebControls.DropDownList
ddlStates)
{
OleDbDataReader rdrStates;
OleDbConnection conRebuttal = Connection();
OleDbCommand cmdRebuttal = new OleDbCommand();
cmdRebuttal.Connection = conRebuttal;
cmdRebuttal.CommandText = "SELECT DISTINCT State FROM USPostalCodes";
conRebuttal.Open();
rdrStates = cmdRebuttal.ExecuteReader
(System.Data.CommandBehavior.CloseConnection);
while (rdrStates.Read())
{
ListItem li =
new ListItem(rdrStates["City"].ToString(),
rdrStates["City"].ToString());
ddlStates.Items.Add(li);
}
rdrStates.Close();
}
Nov 16 '05 #1
3 1524
ja**********@hotmail.com wrote:
The method below belongs to a class. The method accepts a
dropdownlist as a parameter. Is there any disadvantage to passing in
the control and having this method populate it as opposed to passing
back a datareader from this method and having the webform populate it?
You mix user-interface-logic and business logic which has big disadvantages:

Read
http://msdn.microsoft.com/architectu...s/html/Esp.asp

Especially
Model-View-Controller
http://msdn.microsoft.com/architectu...tml/DesMVC.asp
Implementing Model-View-Controller in ASP.NET
http://msdn.microsoft.com/architectu...mpMVCinASP.asp

This will answer your questions.
Oh yea, by the way, it is just passing a pointer to the control,
right? Or should I designate that the parameter as a reference value?


No, it is passed as a reference.

Cheers

Arne Janning

Nov 16 '05 #2
Jay
I am not saying that you are wrong at all. On the other hand, isn't it
mixing user interface logic with business logic when you see code that
accesses the database in the page load event handler? That code exists
everywhere on the net.

I thought that in order not to mix the two, database calls (references)
should not be in the page load which was my initial intent. But then I
ended up having to add a reference to
using System.Web.UI.WebControls in the business logic. That is where my
dilemma begins

Thank You for your comments!

"Arne Janning" <sp*****************@msn.com> wrote in message
news:OS****************@TK2MSFTNGP09.phx.gbl...
ja**********@hotmail.com wrote:
The method below belongs to a class. The method accepts a
dropdownlist as a parameter. Is there any disadvantage to passing in
the control and having this method populate it as opposed to passing
back a datareader from this method and having the webform populate it?
You mix user-interface-logic and business logic which has big

disadvantages:
Read
http://msdn.microsoft.com/architectu...s/html/Esp.asp
Especially
Model-View-Controller
http://msdn.microsoft.com/architectu...tml/DesMVC.asp Implementing Model-View-Controller in ASP.NET
http://msdn.microsoft.com/architectu...mpMVCinASP.asp
This will answer your questions.
Oh yea, by the way, it is just passing a pointer to the control,
right? Or should I designate that the parameter as a reference value?


No, it is passed as a reference.

Cheers

Arne Janning

Nov 16 '05 #3
Jay
I guess that my real concern is about this concept of seperation of
user-interface and business logic. I want it to be completely seperate!
What I mean is that I want no database objects in my user-interface like a
..NET datareader. I think a dataset is much more conforming to the rules. A
dataset is XML, where as a datareader is a data object. My concepts is that
all data objects should be in the business logic. Take for example mobile
applications. Do I want my mobile unit to have to support ADO.NET

Is there a reason to use a datareader than a dataset. Does a dataset take
up much more memory?

My original post is concerning the code that I wrote to get the datareader
out of the user interface. But then by doing that I was putting
user-interface stuff in the business logic. I In specific I was passing a
generic dropdownlist as a parameter.

Can you see my delimma here?
"Arne Janning" <sp*****************@msn.com> wrote in message
news:OS****************@TK2MSFTNGP09.phx.gbl...
ja**********@hotmail.com wrote:
The method below belongs to a class. The method accepts a
dropdownlist as a parameter. Is there any disadvantage to passing in
the control and having this method populate it as opposed to passing
back a datareader from this method and having the webform populate it?
You mix user-interface-logic and business logic which has big

disadvantages:
Read
http://msdn.microsoft.com/architectu...s/html/Esp.asp
Especially
Model-View-Controller
http://msdn.microsoft.com/architectu...tml/DesMVC.asp Implementing Model-View-Controller in ASP.NET
http://msdn.microsoft.com/architectu...mpMVCinASP.asp
This will answer your questions.
Oh yea, by the way, it is just passing a pointer to the control,
right? Or should I designate that the parameter as a reference value?


No, it is passed as a reference.

Cheers

Arne Janning

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tom Gao | last post by:
hi guys I'm wondering how do I pass a key-value pair to a drop downlist ? since I can not use hashtable as there is nor order.. and I can not use sortedlist as the order which I supply to the...
2
by: Russ | last post by:
I have a page with 2 drop down lists, when a user selects something in the first dropdownlist the contens of the second change. How do I clear out all the list items in the second drop down list...
1
by: msnews.microsoft.com | last post by:
I'd like to hear your thoughts on best methods for populating drop down list controls. I have states and countries drop down lists that don't change often, so naturally I "hard code" them in the...
7
by: Markus McGee | last post by:
Hi all, I have a quick question...I believe. On my web page, call it page A, I have a drop downlist with runat server enabled. When the drop downlist change event occurs it repopulates a...
4
by: Rudy | last post by:
Hello! I have 4 diffrent drop downlist. I want a user to select a value from a drop down list, and place it in a SELECT statement. How would I put that value in the select statement. And if the...
1
by: MasterChief | last post by:
I am using a gridview and having it display what is selected in a drop-down list. How do I set it so the gridview will show all by default. I have added an ALL.. item to the item collection of the...
3
by: Yi Chen | last post by:
We have a drop down list on a PHP page, with several product names, and when people click one item, we will refresh the same page with the product name as parameter, and in turn we want to include...
1
by: 47computers | last post by:
I have a couple of DropDownLists in a DetailsView control (your classic country/state lists) and I need one to be populated based on the current selection of the other. Currently this works fine...
2
by: myquestion | last post by:
how to hide/show a text box using drop downlist in php
2
by: Hugh | last post by:
The PyGUI website specified this place as the place for general discussion about it, so here goes.... First off - thanks for something that is so straightforward to get running on OSX... I've...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.