473,654 Members | 3,107 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.Se lectedItem; }
}

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

public void Employee_DDL_Lo ad(ref string MessageText)
{
IDataReader myCategories = null;
CommonHelper.Ex ecuteCommonRead er(ref myEmployee,
"ES_Employee_Ge tEmployees", ref MessageText);
DDL_Employee.Da taTextField = "Employee";
DDL_Employee.Da taValueField = "EmployeeID ";
DDL_Employee.Da taSource = myCategories;
DDL_Employee.Da taBind();
DDL_Employee.It ems.Insert(0, new ListItem("-- Select
Employee--", "0"));
}
Aug 7 '06 #1
2 2397
Bryan,

see if this will help.

a) create a class 'UserControlBas e' that will subclass
System.Web.UI.U serControl.
b) Move common code to 'UserControlBas e' class.
c) Inherit 'UserControlBas e' 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.Se lectedItem; }
}

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

public void Employee_DDL_Lo ad(ref string MessageText)
{
IDataReader myCategories = null;
CommonHelper.Ex ecuteCommonRead er(ref myEmployee,
"ES_Employee_Ge tEmployees", ref MessageText);
DDL_Employee.Da taTextField = "Employee";
DDL_Employee.Da taValueField = "EmployeeID ";
DDL_Employee.Da taSource = myCategories;
DDL_Employee.Da taBind();
DDL_Employee.It ems.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.Gene ric_DDL_Load(); // fills the office ddl

EmployeeDDL1.Em ployee_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 'UserControlBas e' that will subclass
System.Web.UI.U serControl.
b) Move common code to 'UserControlBas e' class.
c) Inherit 'UserControlBas e' 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.Se lectedItem; }
}

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

public void Employee_DDL_Lo ad(ref string MessageText)
{
IDataReader myCategories = null;
CommonHelper.Ex ecuteCommonRead er(ref myEmployee,
"ES_Employee_Ge tEmployees", ref MessageText);
DDL_Employee.Da taTextField = "Employee";
DDL_Employee.Da taValueField = "EmployeeID ";
DDL_Employee.Da taSource = myCategories;
DDL_Employee.Da taBind();
DDL_Employee.It ems.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
5837
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 module Dim WithEvents tc As testControl 'button1_click (for example)
1
3446
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 experience with databases (hate being a n00b) but I'm currently attempting to put myself through some sort of crash course.. How far have I got? Ok so using MS access 2003. I have a table (table1) with data with a
2
7116
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 be able to drag-and-drop to the treeview from outside the UserControl. Now, when I drag over the treeview in the UserControl, the UserControl gets the drag-and-drop events, but the treeview doesn't. Is there a simple way to pass drag-and-drop...
3
6154
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 that appear when user clicks the drop-down arrow button. Because items in the Drop down list are a little long, user can't see the full thing when they pull down the items from the drop down list.
2
12611
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 select any skill in 1st drop down list then i'll select % of this skill in the 2nd list box , based on the percentage i've selected in the 2nd list box it has to display 2 sets of drop down list boxes at run time one for selecting skill and
8
7568
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, ProductName, CategoryID, from tblCategoryProducts Where (CategoryID = @CategoryID)
5
2814
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 create a class file for the user control to subclass this out. Something basic for a start, just initializing things. When I drag this custom control from the Toolbox to my form then Visual Studio just abruptly exits without warning. So I...
6
1934
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 control and fixed it. But it still doesn't work for the controls already added to the form. It works fine for new instances of the control dragged from the toolbox to the form. I don't want to have to drag and drop new controls to exchange all my old...
4
1319
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 and paste a usercontrol. What happens is that the controls inside the usercontrol are being created on the form in addition to the copy of the usercontrol. I'm using VS 2008 Pro, v9.0.21022.8 with .NET 3.5. Here's how I can duplicate the...
0
8375
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8707
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8593
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6161
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2714
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1593
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.