Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using webgrid to display data from the database.
I am create a database entity model class which has fields of the table.
I am creating another model class which is calling data from a stored procedure and entering into database entity model class's list.
I am creating a partial view to display webgrid.
Can anyone help me with this?
Posted
Comments
Zoltán Zörgő 1-Feb-13 2:55am    
What help do you want since you are doing all this already. Don't you?
Start here: http://msdn.microsoft.com/en-us/magazine/hh288075.aspx

1 solution

C#
<p>WebGrid Example With textbox and checkbox</p>
<% var list = new[]
                    {
                        new { StudentId = 1, Name = "Name1", Cond = true },
                        new { StudentId = 2, Name = "Name3", Cond = false },
                        new { StudentId = 3, Name = "Name3", Cond = true },
                        new { StudentId = 4, Name = "Name4", Cond = true },
                        new { StudentId = 5, Name = "Name5", Cond = false },
                        new { StudentId = 6, Name = "Name6", Cond = true },
                        new { StudentId = 7, Name = "Name7", Cond = true },
                        new { StudentId = 8, Name = "Name8", Cond = true },
                        new { StudentId = 9, Name = "Name9", Cond = true },
                        new { StudentId = 10, Name = "Name10", Cond = true },
                        new { StudentId = 11, Name = "Name11", Cond = true }
                    };
    WebGrid studentGrid = new WebGrid(list);
    //studentGrid.Bind(list, autoSortAndPage: true, rowCount: 3); 
%>
<%=
studentGrid.GetHtml(htmlAttributes: new { id = "grid" },
       alternatingRowStyle: "altrow",
       mode: WebGridPagerModes.All,
       firstText: "<<First",
       previousText: "<Previous",
       lastText: "Last>>",
       nextText: "Next >",
columns: 
    new WebGridColumn[]
        {
            studentGrid.Column("StudentId", "Id"),
            studentGrid.Column("Name", "Name"),
            studentGrid.Column(columnName: "Name", header: "Name", format: (item) => Html.TextBox("st")),
            studentGrid.Column(columnName: "Name", header: "Name", format: x => Html.CheckBox("ts")),
            studentGrid.Column(header: "Action",  
                format: item =>
                {
                    string span = "<span class=\"1\" id=\"{0}\">{1}<span>";
                    string action = item.Cond ? "Select" : "Remove";
                    return Html.Raw(string.Format(span, item.StudentId, action));
                }),
            studentGrid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.Cond })), 
            studentGrid.Column(format:(item) => Html.ActionLink("Delete", "Delete", null, new {onclick=string.Format("deleteRecord('Cart', '{0}')", item.Cond), @class="Delete", href="JavaScript:void(0)"}))  

        })
%>
 
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