首頁  >  文章  >  後端開發  >  解析WebGrid - 非常有用的 ASP.NET Web 幫助器

解析WebGrid - 非常有用的 ASP.NET Web 幫助器

零下一度
零下一度原創
2017-05-25 09:42:342306瀏覽

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>

使用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>

【相關推薦】

1. ASP.NET免費影片教學

#2. 分享ASP.NET學習筆記(8)WebPages 幫助器

3. 分享ASP.NET學習筆記(7)WebPages 物件詳解

4. 詳細介紹ASP.NET MVC--檢視

#5. ASP.NET的簡單定義與介紹

以上是解析WebGrid - 非常有用的 ASP.NET Web 幫助器的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn