|
In this chapter, we moved away from using the two data controls that are supplied with Web Matrix, SqlDataSourceControl and MxDataGrid, to show you how we can use the more generic controls that are part pf the .NET Framework in our ASP.NET pages. We discussed why it is that we need to move up a gear, and write code to use data binding with the ASP.NET list controls.
To be able to write this kind of code, you have to know at least a bit about the .NET data-access objects. We looked at these in overview, as well as explaining the difference between the two types of object that we can return from a function or method – the DataReader and the DataSet.
As you saw, Web Matrix helps out where it can when we come to write data-access code by providing code builders that can do most of the work for us. We examined the SELECT Data Method code builder, and used it to generate a function that can extract data from a database table and return it to us as a DataReader object. Then, we bound this to a DataGrid control, and displayed the data. We also showed you how we can make the output more attractive using the Auto Format Wizard or by setting individual style properties.
The next stage was to see how we use the SELECT Data Method code builder to return a DataSet object, and at the same time select only the columns and rows we want. We built a simple page that allows you to enter a search string and find all the rows that match the criteria you specify.
Finally, we moved on to take a brief overview of the other .NET Framework list controls, and used them in an example page. We populated each one using data binding, and examined the output that they generate. All this should help you to choose the appropriate list control for your own pages.
In this chapter, we have covered:
How ASP.NET exposes data that we can use with a range of standard .NET controls
How we create code routines that can access a database and return data
How we select individual columns and return specific sets of rows from a database
How we can use some of the generic .NET Framework data controls to display data
In the next chapter, we'll take a look at linking pages together to form a website, rather than a collection of individual web pages.
|