Easy Tutorial
❮ Webpages Global Prop Webcontrol Standard Borderstyle ❯

ASP.NET Web Pages - WebGrid Helper


WebGrid - One of the many useful ASP.NET Web helpers.


Custom HTML

In previous sections, you displayed database data using Razor code, and all HTML markup was written by hand:

Database Example

@{
var db = Database.Open("SmallBakery"); 
var selectQueryString = "SELECT * FROM Product ORDER BY Name"; 
}
@foreach(var row in db.Query(selectQueryString))
{
@row.Id </td> @row.Name </td> @row.Description </td> @row.Price </td> 
}

Using the WebGrid Helper

The WebGrid helper provides a simpler way to display data.

WebGrid helper:

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); 
}
@grid.GetHtml()
❮ Webpages Global Prop Webcontrol Standard Borderstyle ❯