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>