subclass a usercontrol, drop down list control

  • Thread starter Thread starter bryan
  • Start date Start date
B

bryan

Hi all,

I am developing a web app in .net 2.0.

I have a few DropDownLists that are used on multiple web forms, these
show shop locations and employees.

Each DDL is placed inside a Usercontrol and the user controls are
placed on the relevant pages.

In order to get at some of the properties of the DDLs from their host
web forms I have written methods and properties like the following -

public ListItem SelectedItem
{
get { return DDL_Employee.SelectedItem; }
}

public IDataReader DataSource // set the data source od the DDL
{
get { return _dataSource; }
set { _dataSource = value; }
}

public void Employee_DDL_Load(ref string MessageText)
{
IDataReader myCategories = null;
CommonHelper.ExecuteCommonReader(ref myEmployee,
"ES_Employee_GetEmployees", ref MessageText);
DDL_Employee.DataTextField = "Employee";
DDL_Employee.DataValueField = "EmployeeID";
DDL_Employee.DataSource = myCategories;
DDL_Employee.DataBind();
DDL_Employee.Items.Insert(0, new ListItem("-- Select
Employee--", "0"));
}
 
Bryan,

see if this will help.

a) create a class 'UserControlBase' that will subclass
System.Web.UI.UserControl.
b) Move common code to 'UserControlBase' class.
c) Inherit 'UserControlBase' class 'Shop', 'Employee' user controls.

Will this work?

Regards,
Augustin
 
Hi Augustin,

I think that is not as easy as I would hope...the DDL on
UserControlBase will not appear on the subclass. I have read a few
things about this.

Solved my problem another way - created a generic user control with a
drop down list inside it.

It contains genreric properties and methods like those described and
some special methods for filling certain DDLs, e.g. I use the generic
fill method to fill the offices, but to fill the employee ddl I need
more complicated logic...this is done in a second fill method.

OfficeDDL1.Generic_DDL_Load(); // fills the office ddl

EmployeeDDL1.Employee_DDL_Load(officeID) // fills the employee ddl


Thanks for your help.

Bryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top