ASP.NET 教程login
ASP.NET 教程
作者:php.cn  更新時間:2022-04-11 14:18:18

網頁 WebGrid


ASP.NET Web Pages - WebGrid 說明器


#WebGrid - 眾多有用的 ASP.NET Web 幫助器之一。


自己寫的HTML

在前面的章節中,您使用Razor 程式碼顯示資料庫數據,所有的HTML 標記都是手寫的:

實例

@{
var db = Database.Open("SmallBakery"); 
var query = "SELECT * FROM Product"; 
}
<html> 
<body> 
<h1>Small Bakery Products</h1> 
<table border="1" width="100%"> 
<tr>
<th>Id</th> 
<th>Product</th> 
<th>Description</th> 
<th>Price</th> 
</tr>
@foreach(var row in db.Query(query))
{
<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 表格來顯示資料
  • 支援不同的格式化選項
  • 支援資料分頁顯示
  • 支援透過點擊清單標題進行排序

實例

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

執行實例»

點擊"運行實例" 按鈕查看線上實例

##### #

PHP中文網