Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MVC
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 31-Jan-13 20:45pm
Comments
Zoltán Zörgő at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

 
<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)"}))  
 
        })
%>
 
  Permalink  
v2

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

  Print Answers RSS
0 CPallini 550
1 Sergey Alexandrovich Kryukov 420
2 George Jonsson 288
3 Pheonyx 218
4 OriginalGriff 200
0 OriginalGriff 4,813
1 CPallini 3,850
2 Sergey Alexandrovich Kryukov 3,224
3 George Jonsson 2,552
4 Gihan Liyanage 2,186


Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100