|
This post originated from an RSS feed registered with .NET Buzz
by Darrell Norton.
|
Original Post: DataBinding in .NET 2.0
Feed Title: Darrell Norton's Blog
Feed URL: /error.htm?aspxerrorpath=/blogs/darrell.norton/Rss.aspx
Feed Description: Agile Software Development: Scrum, XP, et al with .NET
|
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Darrell Norton
Latest Posts From Darrell Norton's Blog
|
|
The databinding support for the .NET Framework version 1.x was the primary reason for using a DataSet. Using it made life much easier, and trying to develop non-DataSet components was correspondingly harder.
But thatâs all changed in .NET 2.0. You can bind to a business object very simply. First, you need to add a DataConnector for your business object to your form (or user control). Then, the following three lines of code (this is with Windows Forms, it may be slightly different for ASP.NET 2.0):
// Business Object DataConnector
this.BusinessObjectDataConnector =
new System.Windows.Forms.DataConnector(this.components);
this.BusinessObjectDataConnector.DataSource =
Services.BusinessObject.BusinessObjectDataClass.Load();
// DataBindings
this.textbox1.DataBindings.Add(
new Binding("Text", this.BusinessObjectDataConnector,
"SomeProperty", true) );
Thatâs it! Now if you change the value of textbox1, it updates the BusinessObjectâs SomeProperty value for you!
Read: DataBinding in .NET 2.0