Library tutorials & articles

Implementing two-way Data Binding for ASP.NET

Introduction

ASP.NET has raised the bar for Web development considerably with very rich developer functionality built into a flexible and highly extensible object model. For developers who come from a background of hand coding ASP or other scripting or CGI style technology .Net seems almost too good to be true as it reduces a lot of redundant code and simplifies the development process significantly. But one area – simple data binding for controls like textboxes, checkboxes, radio buttons and so on leave a lot to be desired both in terms of ease of use for binding the data as well as providing the ability to read the data back into the data source. In this article Rick examines what's wrong with simple data binding and provides a set of subclasses that make data binding a lot quicker requiring much less manual code.

Data binding tends to be one of the tasks that most developers deal with on a daily basis. Most applications are data centric and whenever you create user interface code that relates to the data you'll find that if you use the default mechanisms of the .Net Framework that you'll do the same things over and over again. Not only that, but .Net really doesn't make data binding as easy as it should be either in Windows Forms or in ASP. Net. In this article, I'll describe briefly how data binding in ASP. Net works and then offer a solution to make the process of data binding much easier by using subclassed controls that handle the repetitive tasks. In a future article I'll then discuss the same issues in Windows Forms.

If you're coming from an ASP or other Web Development background, you're probably thinking “what is Rick talking about?” Data binding in ASP.NET is a huge improvement over whatever I had to do previously in Web forms. After all we do have a form of data binding (actually several forms) in .Net and we have various forms of state management that automatically assign our control values back to the controls so we're free of having manually populate fields with data. Big improvement for sure.

Comments

  1. 16 Jan 2006 at 15:20

    wow,
    absolute great. It helped me a lot in creating forms during runtime. All controls had to generated from database information. So I neede a way to check bind the values by looping through the whole control collection.


    Thanks a lot  
    http://www.developerfusion.co.uk/forums/images/icon8.gif
    http://www.developerfusion.co.uk/forums/images/icon
    8.gif


    Stefan

  2. 01 Feb 2005 at 09:33

    Great stuff!!!
    I find your article really usefull.

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Implementing two-way Data Binding for ASP.NET.

Leave a comment

Sign in or Join us (it's free).

Rick Strahl

Related podcasts

Events coming up

  • Mar 15

    DevWeek 2010

    London, United Kingdom

    DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET 4.0, Silverlight 3, WCF 4, Visual Studio 2010, REST, Windows Workflow 4, Thread Synchronization, ASP.NET 4.0, SQL Server 2008 R2, LINQ, Unit Testing, CLR & C# 4.0, .NET Patterns, WPF 4, F#, Windows Azure, ADO.NET, Entity Framework, Debugging, T-SQL Tips & Tricks, and more.

We'd love to hear what you think! Submit ideas or give us feedback