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();
}