ASP.NET Web Pages - WebGrid Helper
The WebGrid - one of many useful ASP.NET Web helpers.
Hand-written HTML
In previous chapters, you used Razor code to display database data, and all the HTML markup was hand-written:
Database Example
@{
var db = Database.Open("SmallBakery");
var selectQueryString = "SELECT * FROM Product ORDER BY Name";
}
Small Bakery Products
@foreach(var row in db.Query(selectQueryString))
{
}
| Id | Product | Description | Price |
|---|---|---|---|
|
@row.Id |
@row.Name |
@row.Description |
@row.Price |
Run Example »
Using the WebGrid Helper
The WebGrid helper provides a simpler way to display data.
The WebGrid helper:
- Automatically creates an HTML table to display data
- Supports different formatting options
- Supports data paging
- Supports sorting by clicking column headings
WebGrid Example
@{
var db = Database.Open("SmallBakery") ;
var selectQueryString = "SELECT * FROM Product ORDER BY Id";
var data = db.Query(selectQueryString);
var grid = new WebGrid(data);
}
Small Bakery Products
@grid.GetHtml()
Run Example »