Latest web development tutorials

ASP.NET Web Pages WebGrid

WebGrid - uno dei tanti utile ASP.NET Web Helper.


Scrivi la tua HTML

Nella sezione precedente, si è utilizzato il codice Razor visualizza i dati del database, tutti i tag HTML sono scritti a mano:

istanza di database

@{
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 align="right"> @row.Price </td>
</tr>
}
</table>
</body>
</html>

esempio »Esecuzione


Usa WebGrid Helper

WebGrid aiutante fornisce una semplice visualizzazione più dati.

WebGrid aiutante:

  • crea automaticamente una tabella HTML per visualizzare i dati
  • Esso supporta diverse opzioni di formattazione
  • i dati di supporto Impaginazione
  • Supporto ordinare l'elenco cliccando sul titolo

esempio 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>Displaying Data Using the WebGrid Helper</title>
</head>
<body>
<h1>Small Bakery Products</h1>
<div id="grid">
@grid.GetHtml()
</div>
</body>
</html>

esempio »Esecuzione