Using the .NET DataView Object
When building database driven web applications, presentation of data becomes a key component in your web forms. The common problem that arises is that no two users want to view their data the same way. One user wants to see only certain data; another user wants the data sorted by date ascending while another may only want to see data from the past week. The possibilities are literally endless.
As a developer, how do you cover all the scenarios? The answer is you really can’t, what you can do however is offer enough flexibility in data filtering to allow the user to customize their presentation themselves. And depending on what components you are implementing in your application, the DataView object is a good solution to provide this type of filtering.
In this tutorial we’ll look at a basic ASP.NET application that implements data column filtering as well as row state filtering. We’ll use a DataGrid component to search a column for data that matches a search pattern, thus filtering the user’s view. And we’ll also see how we can use the DataView to show only newly added rows; a pattern which can also be applied to edited or deleted rows easily.
We’ll need a sample database to work with so we’ll use the Northwind database which comes with all versions of SQL server, including MSDE. If you do not have access to SQL server you can simply link the tutorial example to any database of your choice and skip the database configuration section.
Note: Visual Studio .NET running ASP.NET 1.1 is required for this tutorial. Both VB.NET and C# code samples will be provided.