Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Bind gridview in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 37
    Comment on it

    While display set of records we always use gridview

     

    In MVC we also have gridview for displaying records or group in a formatted way

     

    For doing that we can do it in a series of ways one way is to bind the view directly with the database and its associated table

     

    @{
    var db = Database.Open("DemoDB"); 
    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 style="text-align:right">@row.Price</td> 
    </tr> 
    }
    </table> 
    </body> 
    </html>

     

    This will show data in the following format

     

    Id Product Description Price
    1 Bread Baked fresh every day 2.99
    2 Strawberry Cake Made with organic strawberries 9.99
    3 Apple Pie Second only to your mom's pie 12.99
    4 Pecan Pie If you like pecans, this is for you 10.99
    5 Lemon Pie Made with the best lemons in the world 11.99
    6 Cupcakes Your kids will love these 9.9

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: