ASP.NET WebページのWebGrid
WebGridの - 多くの有用なASP.NETのWebヘルパーの一つ。
独自のHTMLを書きます
前のセクションでは、カミソリのコードを使用しているデータベースのデータが表示され、すべてのHTMLタグが手書きのとおりです。
データベース・インスタンス
@{
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>
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>
実行中のインスタンス»
WebGridのヘルパーを使用します
WebGridのヘルパーは、単純な表示、より多くのデータを提供します。
WebGridのヘルパー:
- 自動的にデータを表示するHTMLテーブルを作成し、
- これは、異なる書式設定オプションをサポートしています
- ページネーション・サポート・データ
- サポートは、タイトルをクリックして、リストを並べ替えます
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>
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>
実行中のインスタンス»