Click here to Skip to main content
15,886,100 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to show data in webgrid from database. i am use in sql database. programming language c#

please help.
Posted
Comments
Zoltán Zörgő 14-Dec-13 7:47am    
What have you tried? Are you using an ORM to access data or you want (for any reason) ADO.NET?
ashok prajapati 11 15-Dec-13 2:19am    
you need to add some more info what you are doing, what technology you are using or some of the code sample in which you are having problem.

1 solution

select all rows from database into a list/Collection of Model. When you call the view, you have to call it by
C#
View(collectionOfModel);

on view page, declare
HTML
@model IEnumerable<model>
</model>

Define header and user foreach using razor...
C#
<div class="datagrid">
    <table>
        <thead>
            <tr>
                <th>Mobile No
                </th>
            
                <th>Home Phone No
                </th>
                
                <th></th>
            </tr>
        </thead>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.MobileNo)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.HomePhoneNo)
                </td>                      
                 <td>
                    @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
                    @Html.ActionLink("Details", "Details", new { id = item.Id }) |
                    @Html.ActionLink("Delete", "Delete", new { id = item.Id })
                </td>
            </tr>
        }

    </table>
</div>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900