By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,109 Members | 993 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,109 IT Pros & Developers. It's quick & easy.

Populating a drop downlist

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.