Parse WebGrid - Very useful ASP.NET web helper

零下一度
Release: 2017-05-25 09:42:34
Original
2356 people have browsed it

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>
Copy after login

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>
Copy after login

[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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template