public List <string> GetColumns() { if (HttpContext.Current.Session["current_Viewable"] == null) { List <string> failure = new List <string>(); failure.Add("No Columns Detected"); return(failure); } else { CNTR_Viewable view = (CNTR_Viewable)Session["current_Viewable"]; int selected = (int)Session["hidden_field"]; List <Form_able> masterList = (List <Form_able>)Session["master_Forms_List"]; DataTable dt = (DataTable)view.getView(masterList[selected], 0, 0, 1, 0, "", "", out int filteredCount); //Session["dt"] = dt; dt.Columns.Add(new DataColumn("Options")); List <string> data_Columns = new List <string>(); foreach (DataColumn data_Column in dt.Columns) { data_Columns.Add(data_Column.ColumnName); } return(data_Columns); } }
public void GetData(int draw, int start, int length) { int order = Convert.ToInt32(HttpContext.Current.Request["order[0][column]"]); string direction = HttpContext.Current.Request["order[0][dir]"]; string search = HttpContext.Current.Request["search[value]"]; CNTR_Viewable view = (CNTR_Viewable)Session["current_Viewable"]; int selected = (int)Session["hidden_field"]; List <Form_able> masterList = (List <Form_able>)Session["master_Forms_List"]; EventLog.WriteEntry("ICSNET", "Getting Data"); if (length == -1) { length = view.getCount(); } EventLog.WriteEntry("ICSNET", "Getting View"); DataTable dt = (DataTable)view.getView(masterList[selected], 0, start, length, order, search, direction, out int filteredCount); EventLog.WriteEntry("ICSNET", "Retrieved View"); dt.Columns.Add(new DataColumn("Options")); StringBuilder jsonString = new StringBuilder(); DataSet data_Set = new DataSet(); data_Set.Merge(dt); string list_Data = "[]"; if (data_Set != null && data_Set.Tables[0].Rows.Count > 0) { jsonString.Append("["); for (int i = 0; i < dt.Rows.Count; i++) { jsonString.Append("{"); for (int k = 0; k < data_Set.Tables[0].Columns.Count; k++) { if (k < data_Set.Tables[0].Columns.Count - 1) { jsonString.Append("\"" + data_Set.Tables[0].Columns[k].ColumnName.ToString() + "\":" + "\"" + data_Set.Tables[0].Rows[i][k].ToString() + "\","); } else if (k == data_Set.Tables[0].Columns.Count - 1) { jsonString.Append("\"" + data_Set.Tables[0].Columns[k].ColumnName.ToString() + "\":" + "null"); } } if (i == dt.Rows.Count - 1) { jsonString.Append("}"); } else { jsonString.Append("},"); } } jsonString.Append("]"); list_Data = jsonString.ToString(); } string modified_Data = "{ \"draw\": " + draw.ToString() + ",\"recordsTotal\": " + view.getCount().ToString() + ",\"recordsFiltered\": " + filteredCount.ToString() + ", \"data\": " + list_Data + "}"; /*var xdoc = XDocument.Parse(list_Data); * var items = xdoc.Descendants("Item") * .ToDictionary(i => (string)i.Attribute("Key"), * i => (string)i.Attribute("Value")); * var jsonserializer = new System.Web.Script.Serialization.JavaScriptSerializer(); * string json = jsonserializer.Serialize(items);*/ HttpContext.Current.Response.Write(modified_Data); }