Home  >  Article  >  Backend Development  >  Parse WebGrid - Very useful ASP.NET web helper

Parse WebGrid - Very useful ASP.NET web helper

零下一度
零下一度Original
2017-05-25 09:42:342306browse

WebGrid - One of many useful ASP.NET web helpers.

Written HTML

In the previous chapter, you used Razor code to display database data. All HTML tags were handwritten:

Database Example

@{
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>

Using the WebGrid Helper

The WebGrid Helper provides an easier way to display data.

WebGrid Helper:

Automatically create an HTML table to display data

Support different formatting options

Support data paging display

Support sorting by clicking on the list title

WebGrid instance

@{ 
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>

[Related recommendations]

1. ASP.NET Free Video Tutorial

2. Share ASP.NET study notes (8) WebPages Helper

3. Share ASP.NET study notes (7) WebPages object detailed explanation

4. Detailed introduction to ASP.NET MVC--View

5. A brief definition and introduction to ASP.NET

The above is the detailed content of Parse WebGrid - Very useful ASP.NET web helper. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn