1. Simple gridview list display and gridview list display
1. HomeController
1 public ActionResult Index () 2 {3 // return the index bound to models. cshtml 4 return View (NorthwindDataProvider. getDocuments ()); 5} 6 7 // <summary> 8 // return method code 9 // </summary> 10 // <returns> </returns> 11 public ActionResult GridViewPartialView () 12 {13 // partial refresh and bind models14 return PartialView ("GridViewPartialView", NorthwindDataProvider. getDocuments (); 15}
2. view (index. cshtml)
1 <div id="GridViewPartialView">2 @Html.Partial("GridViewPartialView", Model)3 </div>
3. view (GridViewPartialView. cshtml)
1 @ * DXCOMMENT: Configure GridView * @ 2 @ Html. devExpress (). gridView (3 settings => 4 {5 settings. name = "GridView"; 6 settings. callbackRouteValues = new {Controller = "Home", Action = "GridViewPartialView"}; 7 settings. keyFieldName = "entid"; 8 settings. width = System. web. UI. webControls. unit. percentage (100); 9 settings. settingsPager. visible = false; 10 settings. settingsPager. pageSize = 20; 11 settings. settings. verticalScrollBarMode = ScrollBarMode. visible; 12 settings. settings. verticalScrollableHeight = 350; 13 settings. settings. verticalScrollBarStyle = GridViewVerticalScrollBarStyle. virtual; 14 settings. controlStyle. paddings. paddingTop = System. web. UI. webControls. unit. pixel (10); 15 settings. controlStyle. border. borderWidth = System. web. UI. webControls. unit. pixel (0); 16 settings. controlStyle. borderBottom. borderWidth = System. web. UI. webControls. unit. pixel (1); 17 // display the serial number column 18 settings. columns. add (c => 19 {20 c. caption = "no."; 21 c. setDataItemTemplateContent (s => 22 {23 ViewContext. writer. write (s. itemIndex + 1); 24}); 25}); 26 // bind a primary key column and hide the column 27 settings. columns. add ("entid ",""). visible = false; 28 settings. columns. add ("DocumentCode", "document font size"); 29 settings. columns. add ("DocumentName", "document name"); 30 // according to '1' or '0' in the database, the data list is 'administrative 'or 'criminal' 31 settings. columns. add (c => 32 {33 c. fieldName = "DocumentType"; 34 c. caption = "type"; 35 c. setDataItemTemplateContent (s => 36 {37 string showText = s. text; 38 if (s. text = "0") 39 {40 showText = ""; 41} 42 else if (s. text = "1") 43 {44 showText = "criminal"; 45} 46 ViewContext. writer. write (showText); 47}); 48}); 49 // format Date: MVCxGridViewColumnType. dateEdit (year/month/day) 50 settings. columns. add (c => 51 {52 c. fieldName = "DocumentDate"; 53 c. caption = "document date"; 54 c. columnType = MVCxGridViewColumnType. dateEdit; 55 c. settings. autoFilterCondition = AutoFilterCondition. equals; 56}); 57 58 settings. columns. add ("DocumentMemo", "Remarks"); 59 // display the check box column 60 settings. commandColumn. visible = true; 61 settings. commandColumn. showSelectCheckbox = true; 62 }). bind (Model ). getHtml ()
GridView