O'Reilly logo

Programming C# 4.0 by Jesse Liberty, Matthew Adams, Ian Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Data Binding

While some of the content in a web application may be fixed, any interesting website will change over time. So it’s highly likely that you’ll want some of the controls on your web page to display data that can change from time to time, and which is probably stored in a database. Many ASP.NET controls can be data-bound, which simplifies display and modification of data.

In the preceding section we hardcoded radio buttons onto a form—one for each of three shippers. That can’t be the best way to do it—relationships with suppliers change, and there’s a good chance that we may want to work with different shippers in the future. We don’t really want to have to go back and rewire the controls each time that kind of business relationship changes. It makes more sense to store the list of shippers in a database, and have the UI reflect that. (In fact, if you’re familiar with Microsoft’s sample databases, you may recognize the three shippers in the earlier examples as the ones provided in the “Northwind” sample database.) This section shows you how you can create these controls dynamically and then bind them to data in the database, by using the RadioButtonList control’s data binding support.

Add a new web form called DisplayShippers.aspx to your project. Put the editor into Split mode. From the toolbox, drag a RadioButtonList onto the new form, either onto the design pane or within the <div> in the Source view.

Note

If you don’t see the radio buttons on the left of your work space, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required