Attribute interpretation
1 DataSource Gets the data source that is bound to the WebGrid
2 Totalrowcount Gets the total row count of data bound to WebGrid
3 PageIndex get WebGrid total pages
4 SortDirection Gets or sets the sort direction of the WebGrid
5 SelectedIndex Gets the index of the WebGrid selection row
public ActionResult Gridview ()
2{
3Daldatacontext da= New Daldatacontext ();
4 var result =da. T_students.tolist ();
5 this= result;
6 return View ();
7 }
1@using mvc3tutorial;
2@model List<T_student>
3@{
4View.title = "Gridview";
5Layout = "~/views/shared/_layout.cshtml";
6}
7
8@{
9var Grid = new WebGrid (Source:model,
10Fieldnameprefix: "Grid_",
11DEFAULTSORT: "Studentname",
12Canpage:true,
13Cansort:true,
14Ajaxupdatecontainerid: "Divgrid",
15PagefieldName: "Paging",
16Sortfieldname: "SortField",
17ROWSPERPAGE:10);
18
19<DivId= "Divgrid">
20@grid. Gethtml (
21stColumns:grid. Columns (
22Grid. Column ("StudentID", "Student ID"),
23Grid. Column ("Studentname", "Student Name"),
24Grid. Column ("Studentcode", "Student Code"),
25Grid. Column ("Sex", "sex"),
26Grid. Column ("Nricpassport", "Nric/passport No.")
27)
28)
29</Div>
30<H2>
31Page Count:
32@Html. Encode (grid. PageCount)
33 <br/>
34 total Record:
35 @Html. Encode (grid. Totalrowcount)
36 </h2>
Span style= "color: #008080;" >37 @Html. Encode (grid. Fieldnameprefix)
38
ASP. MVC3 WebGrid Query Bindings