Chapter 2. Displaying and Editing Data for the Web

In This Chapter

Binding: Displaying data with server-side controls

Creating and using data sources

Repeating through a result set

Creating a data-entry page

When you’re writing the code that displays data on a Web page, it’s worth your time to think carefully through the order in which everything takes place: when the form loads, when the data is read, when the server controls write their text — and when, in the midst of all this, you want to write your data. Further, there’s the practical matter of formatting the data: Do you write out each data item manually — specifying Cascading Style Sheet information and using HTML tags as well — or do you rely on a server control that writes CSS styles for you? Well, that depends. In this chapter I present different ways to get your data out of the database and onto the Web page.

Displaying and Editing Data for the Web

All code listings used in this book are available for download at www.dummies.com/go/aspnetaiofd.

Writing Data to a Page with a Label

A Label server control lets you write dynamic text to a page. But you can also use it to write out data from a database. But why is this any better than just using Response.Write? It’s neither better nor worse, just an alternate way of writing your data with its own pros and cons, which I tell you about here.

Here’s a sample Page_Load event that stores a data item in a Label’s Text property. ...

Get ASP.NET 2.0 All-In-One Desk Reference For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.