ASP.NET Web Pages WebGrid
asp.net web pages - webgrid 幫助器
webgrid - 眾多有用的 asp.net web 幫助器之一。
自己寫的 html
在前面的章節中,您使用 razor 代碼顯示數據庫數據,所有的 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>