13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13: Data Binding 335Try Thisdatabase tables to <strong>ASP</strong>.<strong>NET</strong> controls. When dealing with ADO.<strong>NET</strong> data, you willquickly find that your best <strong>ASP</strong>.<strong>NET</strong> method is the DataBinder.Eval() method. Itis <strong>com</strong>bined with a Container.DataItem parameter to extract and bind a table field(column). The <strong>ASP</strong>.<strong>NET</strong> expressionmakes identifying the data source very easy. Each field in the table has an identifier, andthe data binding requires only that you know the name of the field. So rather than needing<strong>com</strong>plex extraction code, the DataBinder.Eval() method for identifying a datasource makes binding to a database table’s data quite simple.Basic TemplatesThis next example shows how to create a simple yet very clear and attractive table. Toprovide a row and column header, the application uses a thatprovides each column with a label using the table’s column names. You do not have touse the column names supplied in the table, but can use any header name you want. Inaddition to a , you will also be using an tagused in repeating rows for each record. The Repeater control is smart enough to know thatthe only expects one instance, while the expects to be repeated until the table is exhausted.Repeating a TableThe following steps show how to create data binding using a Repeater object:1. Open a new Web Site with the name TableRepeater.2. Open the <strong>ASP</strong>.<strong>NET</strong> portion of the application, and open the Data menu in the Toolbox.3. Drag a Repeater web control to the editor in the container.4. Begin to type

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!