ASP.NET Tutoria...login
ASP.NET Tutorial
author:php.cn  update time:2022-04-11 14:18:18

Web Pages WebGrid


ASP.NET Web Pages - WebGrid Helper


WebGrid - One of many useful ASP.NET Web Helpers.


Written HTML

In the previous chapter, you used Razor code to display database data. All HTML tags were handwritten:

Instance

@{
var db = Database.Open("SmallBakery"); 
var query = "SELECT * FROM Product"; 
}
<html> 
<body> 
<h1>Small Bakery Products</h1> 
<table border="1" width="100%"> 
<tr>
<th>Id</th> 
<th>Product</th> 
<th>Description</th> 
<th>Price</th> 
</tr>
@foreach(var row in db.Query(query))
{
<tr> 
<td>@row.Id</td> 
<td>@row.Name</td> 
<td>@row.Description</td> 
<td align="right">@row.Price</td> 
</tr> 
}
</table> 
</body> 
</html>

Run instance»

Click the "Run instance" button to view the online instance



# #Using the WebGrid helper

The WebGrid helper provides a simpler way to display data.

WebGrid Helper:

  • Automatically create an HTML table to display data

  • Supports different formatting options

  • Support data paging display

  • Support sorting by clicking on the list title

Example

@{ 
var db = Database.Open("SmallBakery") ; 
var query = "SELECT * FROM Product ORDER BY Name"; 
var data = db.Query(query); 
var grid = new WebGrid(data); 
}
<html> 
<head> 
<title>Displaying Data Using the WebGrid Helper</title> 
</head> 
<body> 
<h1>Small Bakery Products</h1> 
<div id="grid"> 
@grid.GetHtml()
</div> 
</body> 
</html>

Run Instance»Click the "Run Instance" button to view the online instance



# #