Chapter 19A. Displaying Data in Web Forms

Many web applications display data from a database. In this lesson I show you how to use the DataLayer that you created in the previous lesson to display data in an ASP.NET Web Forms application.

REFERRING TO THE DATA LAYER

To use the DataLayer from the previous lesson you must first add a reference to the assembly. You can do this a couple of ways:

  1. Add the DataLayer project to the current solution and add a reference to the DataLayer project.

  2. Add a reference to the DataLayer assembly (DLL).

Either way, you need to add the connection string to the web.config file. This is the connection string from Lesson 18:

<add name="RecipeDBEntities" connectionString=
    "metadata=res://*/DataModel.csdl|res:
//*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider
connection string="DataSource=.\SQLEXPRESS;
AttachDbFilename=C:\ASPNETTrainer\DataLayer\Recipes.mdf;IntegratedSecurity=True;
Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True&quot;"
providerName="System.Data.EntityClient" />

So far, I have shown you how to display data by setting the text property of the server control to the value, as shown in the following example:

MyTextBox.Text = value

Now I show you how to use some of the many data bound server controls provided by Microsoft Visual Web Developer 2010 Express.

LIST CONTROLS

List controls are used to display a simple list of items. These are the list controls found on the General tab of the Toolbox:

  • BulletedList ...

Get ASP.NET 4 24-Hour Trainer 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.