Páginas Web ASP.NET - Ayudante WebGrid

WebGrid - una de las muchas utilidades de ayuda ASP.NET.

Escribir HTML

En los capítulos anteriores, mostramos datos de la base de datos utilizando código razor y escribimos todos los marcadores HTML:

Instancia de Database

@{
var db = Database.Open("SmallBakery"); 
var selectQueryString = "SELECT * FROM Product ORDER BY Name"; 
}
<html> 
<body> 
<h1>Productos de Panadería Pequeña</h1> 
<table> 
<tr>
<th>Id</th> 
<th>Producto</th> 
<th>Descripción</th> 
<th>Precio</th> 
</tr>
@foreach(var row in db.Query(selectQueryString))
{
<tr> 
<td>@row.Id</td> 
<td>@row.Name</td> 
<td>@row.Description</td> 
<td aling="right">@row.Price</td> 
</tr> 
}
</table> 
</body> 
</html>

Ejecutar Ejemplo

Usar el ayudante de WebGrid

Usar el ayudante de WebGrid es una manera más sencilla de mostrar datos.

Ayudante de WebGrid:

  • Crea automáticamente una tabla HTML para mostrar los datos
  • Soporta diferentes opciones de formato
  • Soporta paginación de datos
  • Soporta ordenar haciendo clic en los títulos de las columnas

Instancia de WebGrid

@{ 
var db = Database.Open("SmallBakery") ; 
var selectQueryString = "SELECT * FROM Product ORDER BY Id"; 
var data = db.Query(selectQueryString); 
var grid = new WebGrid(data); 
}
<html> 
<head> 
<title>Mostrando Datos Usando el Ayudante WebGrid</title> 
</head> 
<body> 
<h1>Productos de Panadería Pequeña</h1> 
<div id="grid"> 
@grid.GetHtml()
</div> 
</body> 
</html>

Ejecutar Ejemplo