Tuesday, 20 October 2015

ASP.NET MVC WebGrid Helper

ASP.NET MVC - Get the data from database and display as sort-able grid:

.cshtml page
@{
    var db = Database.Open("tutorial");   // db connection string
    var selectQueryString = "SELECT * FROM students ORDER BY id";   // sort by id by default
    var data = db.Query(selectQueryString);
    var grid = new WebGrid(data);
}

<div id="grid">
    @grid.GetHtml()
</div>


Web config database connection string:
<add name="tutorial" connectionString="Data Source=localhost;Initial Catalog=students;Integrated Security=true;" providerName="System.Data.SqlClient"/>


No comments:

Setup Windows Local Account without the Internet

During the Windows setup,  On the WiFi screen, press SHIFT + F10  or  FN + SHIFT + F10  This will open the command prompt window with admini...