A common task for web developers
is to retrieve data and format it for output manually or through technology like ASP.NET data
binding. Starting in ASP.NET 2.0, adding templates and data binding to server controls requires
much less code than in previous versions of ASP.NET. We take advantage of these improvements
in the examples in this chapter.
Data binding dynamically merges a collection of data with a server control at runtime to
produce HTML content representing the data source, as shown in Figure 7-1.
Figure 7-1. Data binding with server controls
Templates and data binding are naturally complementary. Data binding efficiently brings
data into the control, and templates allow customization of how server controls or HTML elements
display the data. Templates and data binding generally are brought together in more advanced
controls, such as the ASP.NET GridView or Repeater server controls, making database-driven
web development quick and easy. Pull a piece of data from the database via ADO.NET or an
IDataSource-based control, bind it to a server control, configure its style properties and templates
resulting in a very appealing HTML display that appears to act like a Visual Basic form with
282 CHAPTER 7 ?– SE RVER CONTROL DATA B INDING
data paging, alternate colors, and so on.
Pages:
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394