Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
User control
Message
From
07/01/2007 00:27:31
 
 
To
06/01/2007 22:36:09
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01183223
Message ID:
01183229
Views:
22
John,

Here's how I do this sort of thing. I have a .DataBind() method in my UserControl that I call after the UserControl is instantiated. If you are dropping the control on a Form, then call the UserControl's .DataBind() method either in the Form's constructor after the InitializeComponent() or in the Form's Load. Your UserControl.DataBind() method would look someething like this:
public void DataBind(DataTable dt)
{
    this.txtAddress.DataBindings.Add("Text", dt, "address");
    this.txtCity.DataBindings.Add("Text", dt, "city");
    // etc.etc.etc.
}
Doing it like this, you don't *need* to access the individual TextBoxes, etc. in the UserControl. But, if you need that functionality for other reasons, all you have to do is create properties in your UserControl.
// the normal declarations when you drop a TextBox on your UserControl
private TextBox txtAddress;
private TextBox txtCity;

// the Properties for those controls that you want to give public access to
public TextBox Address
{
    get {return this.txtAddress;}
    set {this.txtAddress = value;}
}
public TextBox City
{
    get {return this.txtCity;}
    set {this.txtCity = value;}
}
~~Bonnie





>Hi,
>I would like to create an user control that contains textbox for address, city,
>postal, and combobox for state and country.
>
>This user control would auto-populate state list and country list.
>
>Once user place this user control to form, I want to assign databinding source to each of the control.
>
>Anyway to do this?
>
>I created the user control, but I can't "access" textbox and combobox inside the user control. I am not sure my vfp "mind" can be apply to .NET world. How to do this in .NET?
>
>Thank you
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform