public string GetDataTable() { string role = Session["UserRole"] + ""; role = role.ToLower(); string[] coloumns = { "", "UserName", "RoleName", "" }; int echo = Int32.Parse(Request.Params["sEcho"]); int displayLength = Int32.Parse(Request.Params["iDisplayLength"]); int colIndex = Int32.Parse(Request.Params["iSortCol_0"]); int displayStart = Int32.Parse(Request.Params["iDisplayStart"]); string search = (Request.Params["sSearch"] + "").Trim(); var dal = new RoleRepository(); var records = dal.AsQueryable(); int totalRecords = records.Count(); int totalDisplayRecords = totalRecords; var filteredList = records; if (search != "") filteredList = records.Where(p => p.Name.Contains(search) ); var orderedList = filteredList.OrderByDescending(p => p.ID); if (colIndex < coloumns.Length && coloumns[colIndex] + "" != "") { string sortDir = Request.Params["sSortDir_0"]; string sortExpression = coloumns[colIndex] + sortDir; orderedList = sortDir == "asc" ? filteredList.OrderBy(coloumns[colIndex]) : filteredList.OrderByDescending(coloumns[colIndex]); } StringBuilder sb = new StringBuilder(); sb.Clear(); JQueryResponse rs = new JQueryResponse(); foreach (var item in orderedList.Skip(displayStart).Take(displayLength)) { List<string> data = new List<string>(); var method = ""; var disabled = "disabled='disabled'"; if (CanEdit) { method = "onclick='ChangeStatus(this)'"; disabled = ""; } var status = "<img class='icon' src='images/status-online.png' title='Click to make it inactive' " + disabled + method + " data-id='" + item.ID + "' status-id='" + item.RecordStatus + "' />"; if (item.RecordStatus == (byte)RecordStatus.Inactive) status = "<img class='icon' src='images/status-offline.png' title='Click to make it active' " + disabled + method + " data-id='" + item.ID + "' status-id='" + item.RecordStatus + "' />"; data.Add(status); data.Add(item.Name); string editIcon = "<img src='images/edit.png' class='icon' alt='' onclick=\"Edit(" + item.ID + ")\" style='float:left' title='Edit Record' />"; string deleteIcon = "<img id='delete' src='images/delete.png' class='icon' alt='' onclick=\"Delete(" + item.ID + ")\" style='float:right' title='Delete Record' />"; string icons = ""; if (CanEdit) icons = editIcon; if (CanDelete) icons = editIcon + deleteIcon; data.Add(icons); rs.aaData.Add(data); } rs.sEcho = echo; rs.iTotalRecords = totalRecords; rs.iTotalDisplayRecords = totalDisplayRecords; return new JavaScriptSerializer().Serialize(rs); }