Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.28 KB | None | 0 0
  1. <div id="gridContent">
  2. @grid.GetHtml(
  3. fillEmptyRows: true,
  4. tableStyle: "webGrid",
  5. alternatingRowStyle: "alternate-row",
  6. headerStyle: "grid-header",
  7. footerStyle: "grid-footer",
  8. mode: WebGridPagerModes.All,
  9. firstText: "<< First",
  10. previousText: "< Prev",
  11. nextText: "Next >",
  12. lastText: "Last >>",
  13. columns: new[] {
  14. grid.Column("PatientID"),
  15. grid.Column("PatientName"),
  16. grid.Column("Age"),
  17. grid.Column("DOB"),
  18. grid.Column("Sex"),
  19. grid.Column("Phone"),
  20. grid.Column("Mobile"),
  21. grid.Column("City"),
  22. grid.Column("PinCode"),
  23.  
  24. // grid.Column("Dr_Remarks",header:"Remarks",style:"left"),
  25.  
  26.  
  27. //grid.Column("Dr_Add1",
  28. // header: "Bed Count",style:"right"
  29. //),
  30.  
  31. grid.Column("",
  32. header: "Actions",
  33. format: @<text>
  34. @Html.ActionLink("Edit", "EditPatient", new { id = item.PatientID }, htmlAttributes: new { @class = "link" })
  35. |
  36. @Html.ActionLink("Delete", "PatientList", new { id = item.PatientID },
  37. htmlAttributes: new { @class = "link", onclick = "return confirm('Are you sure you wish to delete this record?');" })
  38. </text>
  39. )
  40. })
  41. </div>
  42.  
  43.  
  44. **controller**
  45.  
  46. public ActionResult PatientList(int page = 1, string sort = "Dr_Id", string sortDir = "ASC", int id = 0)
  47. {
  48. if (id != 0)
  49. {
  50. bool isDelete = false;
  51. isDelete = rdm_Patient.DeletePatient(id);
  52.  
  53.  
  54. return View(GetPatient(page, sort, sortDir));
  55. }
  56. else
  57. {
  58. return View(GetPatient(page, sort, sortDir));
  59. }
  60. }
  61.  
  62. private PatientPageViewModel GetPatient(int page = 1, string sort = "Dr_Id", string sortDir = "ASC")
  63. {
  64. const int patientPerPage = 5;
  65. var numPatient = rdm_Patient.CountPatient();
  66. sortDir = sortDir.Equals("desc", StringComparison.CurrentCultureIgnoreCase) ? sortDir : "asc";
  67. var validColumns = new[] { "PatientID", "PatientName" };
  68. if (!validColumns.Any(c => c.Equals(sort, StringComparison.CurrentCultureIgnoreCase)))
  69. sort = "PatientID";
  70. var doctors = rdm_Patient.getpatientpage(page, patientPerPage, "it." + sort + " " + sortDir);
  71. var data = new PatientPageViewModel()
  72. {
  73.  
  74. numberOfPatient = numPatient,
  75. patientPerPage = patientPerPage,
  76. Patient = doctors,
  77. };
  78. return data;
  79. }
  80.  
  81. Index.cshtml:
  82. @model MvcApplication1.Models.Employee
  83. @{
  84. ViewBag.Title = "Index";
  85. }
  86.  
  87. <h2>Index</h2>
  88. <table>
  89. <tr>
  90. <td>
  91. @Html.DropDownList("lstdepartment", Model.Department_List)
  92. </td>
  93. </tr>
  94. <tr>
  95. <td>
  96. <div id="EmployeeViewGrid">
  97. @Html.Partial("EmployeeView",Model.Employee_Grid)
  98. </div>
  99. </td>
  100. </tr>
  101. </table>
  102.  
  103. <script type="text/javascript">
  104. $('#lstdepartment').change(function (e) {
  105. e.preventDefault();
  106. var url = '@Url.Action("Filter")';
  107. $.get(url, { department: $(this).val() }, function (result) {
  108. debugger;
  109. $('#EmployeeViewGrid').html(result);
  110. });
  111. });
  112. </script>
  113.  
  114. Partial view:
  115.  
  116. @model List< MvcApplication1.Models.Employee>
  117. @{
  118. ViewBag.Title = "EmployeeView";
  119. }
  120.  
  121. <h2>EmployeeView</h2>
  122. <div id="gridposition" style="overflow: scroll; height: 300px; overflow-x: hidden;">
  123. @{
  124. var grid1 = new WebGrid(source: Model, canPage: true, rowsPerPage: 5, ajaxUpdateContainerId: "gridContent");
  125.  
  126. @grid1.GetHtml(mode: WebGridPagerModes.All, tableStyle: "webGrid",
  127. headerStyle: "header",
  128. alternatingRowStyle: "alt",
  129. selectedRowStyle: "select",
  130. rowStyle: "description",
  131. htmlAttributes: new { id = "positionGrid" },
  132. fillEmptyRows: false,
  133.  
  134. columns: grid1.Columns(
  135.  
  136. grid1.Column("EmployeeId", header: "EmployeeId"),
  137. grid1.Column("EmpName", header: "EmpName"),
  138. grid1.Column("Age", header: "Age"),
  139. grid1.Column("Department", header: "Department"),
  140. grid1.Column("Salary", header: "Salary")))
  141. }
  142. </div>
  143.  
  144. Controller:
  145.  
  146. using System;
  147. using System.Collections.Generic;
  148. using System.Data;
  149. using System.Data.Entity;
  150. using System.Linq;
  151. using System.Web;
  152. using System.Web.Mvc;
  153. using MvcApplication1.Models;
  154.  
  155. namespace MvcApplication1.Controllers
  156. {
  157. public class EmployeeController : Controller
  158. {
  159. private EmployeeDatabaseEntities1 db = new EmployeeDatabaseEntities1();
  160.  
  161. //
  162. // GET: /Employee/
  163.  
  164. public ActionResult Index()
  165. {
  166. Employee _model = new Employee();
  167. //_model.Employee_Grid = db.tbl_Employee.ToList();
  168. var departmentlist = db.tbl_department.ToList();
  169.  
  170. _model.Department_List = (from d in departmentlist
  171. select new SelectListItem
  172. {
  173.  
  174. Value = d.department_id.ToString(),
  175. Text = d.department_name
  176. }).ToList();
  177.  
  178. var qq = (from e in db.tbl_Employee
  179. join d in db.tbl_department on e.Department_id equals d.department_id
  180. select new Employee
  181. {
  182. Department_id=e.Department_id,
  183. EmployeeId=e.EmployeeId,
  184. EmpName=e.EmpName,
  185. Age=e.Age,
  186. Department=d.department_name
  187. }).ToList();
  188. _model.Employee_Grid = qq;
  189. return View("Index", _model);
  190. }
  191.  
  192.  
  193. public ActionResult Filter(string department)
  194. {
  195. int? department_id = Convert.ToInt32(department);
  196. var qq = (from e in db.tbl_Employee
  197. join d in db.tbl_department on e.Department_id equals d.department_id
  198. where e.Department_id == department_id
  199. select new Employee
  200. {
  201. Department_id = e.Department_id,
  202. EmployeeId = e.EmployeeId,enter code here
  203. EmpName = e.EmpName,
  204. Age = e.Age,
  205. Department = d.department_name
  206. }).ToList();
  207. return PartialView("EmployeeView",qq);
  208. }
  209. }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement