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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass control as ref?

Status
Not open for further replies.

crazyboybert

Programmer
Jun 27, 2001
798
GB
Hi all

Is it possible to pass a control as a ref to a method of another class? For example..
Code:
public void fillList(ref System.Web.UI.WebControls.DropDownList myList){
  //open a database connection and command object
  myList.DataSource = myCommand.ExecuteReader();
  myList.DataBind();
  //close connection
}

then calling method above from webform

System.Web.UI.WebControls.DropDownList myList = new System.Web.UI.WebControls.DropDownList();
namespace.classname.fillList(myList);

I have tried the above but don't seem tobe able to pass a control. I guess you are only allowed to pass variables? Would make sense...Is there anyway other way to databind to a control on a webform from a method in a different class?

Cheers

Rob

------------------------------------

Go placidly amidst the noise and haste,
find what peace there may be in silence.
-Anon

------------------------------------
 
Passing a control by reference should work fine. What error are you getting? Or maybe there is something wrong with the database command?



Mark [openup]
 
Sorry for no reply - been having trouble getting into the forum?

Error is something like...

"Cannot convert System.Web.UI.WebControls.TextBox to type ref System.Web.UI.WebControls.TextBox"

Database command is ok as returns datareader to webform fine but wont accept control as ref to be updated form reader by class...

Any ideas?

Thanks

Rob

------------------------------------

Go placidly amidst the noise and haste,
find what peace there may be in silence.
-Anon

------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top