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



PLEASE DISABLE ADBLOCKER AND SUPPORT US!

Please support us by enabling ads on this page. Refresh

YOU DON'T LIKE ADS, WE ALSO DON'T LIKE ADS!
 
But we have to show ads on our site to keep it free and updated. We have to pay huge server costs, domain costs, CDN Costs, Developer Costs, Electricity and Internet Bill. Your little contribution will encourage us to regularly update this site.