Los últimos tutoriales de desarrollo web
 

ASP.NET Páginas Web - El ayudante WebGrid


WebGrid - Uno de los muchos ayudantes Web ASP.NET útiles.


Haciendo el código HTML usted mismo

En un capítulo anterior, se muestran los datos de bases de datos mediante el uso de razor de código, y haciendo el mismo formato HTML:

Ejemplo Base de Datos

@{
var db = Database.Open("SmallBakery"); 
var selectQueryString = "SELECT * FROM Product ORDER BY Name"; 
}

<html> 
<body> 
<h1>Small Bakery Products</h1> 
<table> 
<tr>
<th>Id</th> 
<th>Product</th> 
<th>Description</th> 
<th>Price</th> 
</tr>
@foreach(var row in db.Query(selectQueryString))
{

<tr> 
<td> @row.Id </td> 
<td> @row.Name </td> 
<td> @row.Description </td> 
<td style="text-align:right"> @row.Price </td> 
</tr> 
}
</table> 
</body> 
</html>
Ejecutar ejemplo »

El uso de WebGrid ayudante

Usando el ayudante WebGrid una manera más fácil para mostrar los datos.

El ayudante WebGrid:

  • Ajusta automáticamente una tabla HTML para mostrar los datos
  • Soporta diferentes opciones de formato
  • Soporta paginación a través de datos
  • Soporta clasificación haciendo clic en los encabezados de columna

Ejemplo WebGrid

@{ 
var db = Database.Open("SmallBakery") ; 
var selectQueryString = "SELECT * FROM Product ORDER BY Name"; 
var data = db.Query(selectQueryString); 
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>
Ejecutar ejemplo »