473,503 Members | 2,152 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

subclass a usercontrol, drop down list control

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"));
}
Aug 7 '06 #1
2 2387
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

"bryan" wrote:
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"));
}
.
.
///plus many other methods and properties

The problem is --- the user control for the shop locations contains
almost identical code as shown for employees. I will soon add other
DDLs for customers, products, etc...

Please advise me on how I can combine all this common code?

Thanks,

Bryan

Aug 7 '06 #2
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
Augustin Prasanna wrote:
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

"bryan" wrote:
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"));
}
.
.
///plus many other methods and properties

The problem is --- the user control for the shop locations contains
almost identical code as shown for employees. I will soon add other
DDLs for customers, products, etc...

Please advise me on how I can combine all this common code?

Thanks,

Bryan
Aug 7 '06 #3

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

Similar topics

7
5833
by: Kate | last post by:
Hi: I have a form with a picture box and some command buttons to make certain shapes appear in the picture box. The shapes are drawn on blank UserControls added like this: 'at top of form...
1
3428
by: Dec | last post by:
Ok to simplify things I'll just give an example. This is pretty much what I want to do (minus the postcode): http://www.perrys.co.uk/usedcar?ID=F5J9BNNBMVK00DF I have relatively little...
2
7108
by: Dave Veeneman | last post by:
Is there a simple way to pass drag-and-drop events to a child control in a UserControl? Here's an example: I have created a UserControl which contains a treeview and some text boxes. I want to...
3
6139
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
2
12595
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
8
7561
by: Ed Dror | last post by:
Hi there ASP.NET 2.0 VB & SQL Express Lest take Northwind Categories Products as example I create a table that hold these two together and I create a stored procedure like select ProductID,...
5
2809
by: gregarican | last post by:
There is a C# CTI app I'm working on using Visual Studio 2005 at revision level 8.0.50727-7600. I need a couple of Windows Form Button controls to emulate line buttons on a telephone. So I went to...
6
1923
by: Johnny Jörgensen | last post by:
I've got a usercontrol derived from a normal ComboBox that contains some special formatting code. On my main form I've got a lot of my custom comboboxes. I discovered a bug in the derived...
4
1312
by: Adam Biser | last post by:
My apologies if this has been discussed before, but using Google and also searching the newsgroup has not given me any insight to this problem. I'm experiencing some strange behavior when I copy...
0
7205
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
7349
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...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.