Razor - Display Data using WebGrid

In this chapter you will learn
  • What is WebGrid?
  • How to display data using WebGrid?
  • Programming Example

What is WebGrid?

WebGrid is new technology to display data in tabular format. It is launch with ASP MVC. It is lightweight, easy to use and works well with Razor Syntax. It adds paging automatically.

How to declare WebGrid?

You can declare WebGrid as follow

    var sqldb=Database.Open("Database Tutorial");
    var sqlquery="SELECT * FROM Library";
    var data=sqldb.Query(sqlquery);
    var grid=new WebGrid(data);

How to display data using WebGrid?

Programming Example

@{   
    var sqldb=Database.Open("Database Tutorial");
    var sqlquery="SELECT * FROM Library";
    var data=sqldb.Query(sqlquery);
    var grid=new WebGrid(data);
}
 
<!DOCTYPE html>
 
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
       @{
           @grid.GetHtml();
       }
    </body>
</html>
  Output
ID BookName Author
1    2    3    >
1 C# Christian Nagel
2 ASP.NET MVC Simone Chiaretta
3 Microsoft SQL Server Paul Turley
4 Android Programming DiMarzio Jerome
5 Scala Janek Bogucki
6 .NET Core 1.0 Christian Nagel
7 Visual Studio 2015 William Penberthy
8 Swift IOS Abhishek Mishra
9 Visual Basic 2015 Bryan Newsome
10 Python Luke Sneeringer

Summary

In this chapter you learned to use WebGrid in Razor Syntax. In the next chapter you will get some programming exercise questions. You must do practice. It will help you to understand Razor Programming more deeply.

More Articles

 

Share your thought