Using the WebGrid helper is an easier way to display data.

The WebGrid helper:

  • Automatically sets up an HTML table to display data
  • Supports different options for formatting
  • Supports paging through data
  • Supports Sorting by clicking on column headings

    WebGrid Example

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



Practice Excercise Practice now