/// <summary> /// 模拟数据库分页(实际项目中请直接使用SQL语句返回分页数据!) /// </summary> /// <returns></returns> private DataTable GetPagedDataTable(int pageIndex, int pageSize, bool?data2) { DataTable source = null; if (data2.HasValue && data2.Value) { source = DataSourceUtil.GetDataTable2(); } else { source = DataSourceUtil.GetDataTable(); } DataTable paged = source.Clone(); int rowbegin = pageIndex * pageSize; int rowend = (pageIndex + 1) * pageSize; if (rowend > source.Rows.Count) { rowend = source.Rows.Count; } for (int i = rowbegin; i < rowend; i++) { paged.ImportRow(source.Rows[i]); } return(paged); }
/// <summary> /// 模拟数据库分页(实际项目中请直接使用SQL语句返回分页数据!) /// </summary> /// <returns></returns> private DataTable GetSortedPagedDataTable(string sortField, string sortDirection, int pageIndex, int pageSize) { DataTable source = DataSourceUtil.GetDataTable2(); // 先排序 DataView view1 = source.DefaultView; view1.Sort = String.Format("{0} {1}", sortField, sortDirection); DataTable sortedTable = view1.ToTable(); // 再分页 DataTable paged = sortedTable.Clone(); int rowbegin = pageIndex * pageSize; int rowend = (pageIndex + 1) * pageSize; if (rowend > sortedTable.Rows.Count) { rowend = sortedTable.Rows.Count; } for (int i = rowbegin; i < rowend; i++) { paged.ImportRow(sortedTable.Rows[i]); } return(paged); }
private void BindGrid1() { if (Grid2.SelectedRowIndex < 0) { return; } int classId = Convert.ToInt32(Grid2.DataKeys[Grid2.SelectedRowIndex][0]); DataTable table = null; if (classId == 101) { table = DataSourceUtil.GetDataTable(); } else { table = DataSourceUtil.GetDataTable2(); } Grid1.DataSource = table; Grid1.DataBind(); UpdateClassDesc(classId); }
private void BindGrid() { DataTable table = DataSourceUtil.GetDataTable2(); Grid1.DataSource = table; Grid1.DataBind(); }
// GET: GridDataUrl/GridDataUrlData public ActionResult Index(bool?data2) { JArray ja = new JArray(); DataTable source = null; if (data2.HasValue && data2.Value) { source = DataSourceUtil.GetDataTable2(); } else { source = DataSourceUtil.GetDataTable(); } foreach (DataRow row in source.Rows) { JObject jo = new JObject(); jo.Add("Id", (int)row["Id"]); jo.Add("Name", row["Name"].ToString()); jo.Add("Gender", (int)row["Gender"]); jo.Add("EntranceYear", (int)row["EntranceYear"]); jo.Add("AtSchool", (bool)row["AtSchool"]); jo.Add("Major", row["Major"].ToString()); jo.Add("Group", (int)row["Group"]); ja.Add(jo); } return(Content(ja.ToString(Newtonsoft.Json.Formatting.None))); }
/// <summary> /// 模拟数据库分页 /// </summary> /// <returns></returns> private DataTable GetPagedDataTable() { int pageIndex = Grid1.PageIndex; int pageSize = Grid1.PageSize; string sortField = Grid1.SortField; string sortDirection = Grid1.SortDirection; DataTable table2 = DataSourceUtil.GetDataTable2(); DataView view2 = table2.DefaultView; view2.Sort = String.Format("{0} {1}", sortField, sortDirection); DataTable table = view2.ToTable(); DataTable paged = table.Clone(); int rowbegin = pageIndex * pageSize; int rowend = (pageIndex + 1) * pageSize; if (rowend > table.Rows.Count) { rowend = table.Rows.Count; } for (int i = rowbegin; i < rowend; i++) { paged.ImportRow(table.Rows[i]); } return(paged); }
private DataTable GetSource(string ddlAtSchool, JArray filteredData) { DataTable table2 = DataSourceUtil.GetDataTable2(); DataView view2 = table2.DefaultView; List <string> filters = new List <string>(); // 表格工具栏中的下拉列表过滤项 if (ddlAtSchool != "-1") { filters.Add(String.Format("AtSchool = {0}", ddlAtSchool)); } // 表头菜单的过滤项 if (filteredData != null && filteredData.Count > 0) { foreach (JObject filteredObj in filteredData) { // 本过滤项是[所学专业]列的过滤项 string columnID = filteredObj.Value <string>("column"); if (columnID == "Major") { JObject item = filteredObj.Value <JObject>("item"); string itemOperator = item.Value <string>("operator"); string itemValue = item.Value <string>("value"); if (!String.IsNullOrEmpty(itemValue)) { string escapedValue = DataSourceUtil.EscapeLikeValue(itemValue); if (itemOperator == "equal") { filters.Add(String.Format("Major = '{0}'", escapedValue)); } else if (itemOperator == "contain") { filters.Add(String.Format("Major LIKE '*{0}*'", escapedValue)); } else if (itemOperator == "start") { filters.Add(String.Format("Major LIKE '{0}*'", escapedValue)); } else if (itemOperator == "end") { filters.Add(String.Format("Major LIKE '*{0}'", escapedValue)); } } } } } if (filters.Count > 0) { // RowFilter的用法:http://www.csharp-examples.net/dataview-rowfilter/ view2.RowFilter = String.Join(" AND ", filters.ToArray()); } return(view2.ToTable()); }
private DataTable GetSource(string ttbSearch, string rblAtSchool) { DataTable table2 = DataSourceUtil.GetDataTable2(); DataView view2 = table2.DefaultView; List <string> filters = new List <string>(); if (!String.IsNullOrEmpty(ttbSearch)) { // RowFilter的用法:http://www.csharp-examples.net/dataview-rowfilter/ filters.Add(String.Format("Name LIKE '*{0}*'", DataSourceUtil.EscapeLikeValue(ttbSearch))); } if (rblAtSchool != "-1") { filters.Add(String.Format("AtSchool = {0}", rblAtSchool)); } if (filters.Count > 0) { // RowFilter的用法:http://www.csharp-examples.net/dataview-rowfilter/ view2.RowFilter = String.Join(" AND ", filters.ToArray()); } return(view2.ToTable()); }
// GET: GridDataUrl/PagingSummaryCurrentPageData public ActionResult Index() { JArray ja = new JArray(); DataTable source = DataSourceUtil.GetDataTable2(); foreach (DataRow row in source.Rows) { int fee = (int)row["Fee"]; int donate = (int)row["Donate"]; JObject jo = new JObject(); jo.Add("Id", (int)row["Id"]); jo.Add("Name", row["Name"].ToString()); jo.Add("Gender", (int)row["Gender"]); jo.Add("EntranceYear", (int)row["EntranceYear"]); jo.Add("AtSchool", (bool)row["AtSchool"]); jo.Add("Major", row["Major"].ToString()); jo.Add("Fee", fee); jo.Add("Donate", donate); ja.Add(jo); } return(Content(ja.ToString(Newtonsoft.Json.Formatting.None))); }
private DataTable GetSortedDataTable(string sortField, string sortDirection) { // 模拟数据排序 DataTable table = DataSourceUtil.GetDataTable2(); DataView view1 = table.DefaultView; view1.Sort = String.Format("{0} {1}", sortField, sortDirection); return(view1.ToTable()); }
/// <summary> /// 模拟返回总项数 /// </summary> /// <returns></returns> private int GetTotalCount(bool?data2) { DataTable source = null; if (data2.HasValue && data2.Value) { source = DataSourceUtil.GetDataTable2(); } else { source = DataSourceUtil.GetDataTable(); } return(source.Rows.Count); }
private DataTable GetClassDetailTable(int classId) { DataTable table = null; if (classId == 101) { table = DataSourceUtil.GetDataTable(); } else { table = DataSourceUtil.GetDataTable2(); } return(table); }
public ActionResult Button1_Click(string[] fields, string source) { var grid1 = UIHelper.Grid("Grid1"); if (source == "source1") { grid1.DataSource(DataSourceUtil.GetDataTable2(), fields); grid1.Attribute("data-source-key", "source2"); } else { grid1.DataSource(DataSourceUtil.GetDataTable(), fields); grid1.Attribute("data-source-key", "source1"); } return(UIHelper.Result()); }
protected void Button2_Click(object sender, EventArgs e) { DataTable table; if (Convert.ToBoolean(ViewState["UseDataSource1"])) { ViewState["UseDataSource1"] = false; table = DataSourceUtil.GetDataTable2(); } else { ViewState["UseDataSource1"] = true; table = DataSourceUtil.GetDataTable(); } Grid1.DataSource = table; Grid1.DataBind(); }
private void AutoBindGrid(string gridSourceKey, JArray gridFields) { var grid1 = UIHelper.Grid("Grid1"); DataTable source = null; if (gridSourceKey == "table1") { source = DataSourceUtil.GetDataTable2(); gridSourceKey = "table2"; } else { source = DataSourceUtil.GetDataTable(); gridSourceKey = "table1"; } grid1.DataSource(source, gridFields); grid1.Attribute("data-source-key", gridSourceKey); }
/// <summary> /// 模拟数据库分页 /// </summary> /// <returns></returns> private DataTable GetPagedDataTable(int pageIndex, int pageSize) { DataTable source = DataSourceUtil.GetDataTable2(); DataTable paged = source.Clone(); int rowbegin = pageIndex * pageSize; int rowend = (pageIndex + 1) * pageSize; if (rowend > source.Rows.Count) { rowend = source.Rows.Count; } for (int i = rowbegin; i < rowend; i++) { paged.ImportRow(source.Rows[i]); } return(paged); }
private JObject GetSummaryData() { DataTable source = DataSourceUtil.GetDataTable2(); int donateTotal = 0; int feeTotal = 0; foreach (DataRow row in source.Rows) { donateTotal += Convert.ToInt32(row["Donate"]); feeTotal += Convert.ToInt32(row["Fee"]); } JObject summary = new JObject(); summary.Add("Fee", feeTotal); summary.Add("Donate", donateTotal); return(summary); }
protected void Button1_Click(object sender, EventArgs e) { DataTable table; if (Convert.ToBoolean(ViewState["UseDataSource1"])) { ViewState["UseDataSource1"] = false; table = DataSourceUtil.GetDataTable2(); } else { ViewState["UseDataSource1"] = true; table = DataSourceUtil.GetDataTable(); } // 重新绑定数据前,先清空高亮的行数据 highlightRows.Text = ""; Grid1.DataSource = table; Grid1.DataBind(); }
// GET: GridDataUrl/PagingSummaryData public ActionResult Index() { JObject result = new JObject(); int feeTotal = 0, donateTotal = 0; JArray ja = new JArray(); DataTable source = DataSourceUtil.GetDataTable2(); foreach (DataRow row in source.Rows) { int fee = (int)row["Fee"]; int donate = (int)row["Donate"]; JObject jo = new JObject(); jo.Add("Id", (int)row["Id"]); jo.Add("Name", row["Name"].ToString()); jo.Add("Gender", (int)row["Gender"]); jo.Add("EntranceYear", (int)row["EntranceYear"]); jo.Add("AtSchool", (bool)row["AtSchool"]); jo.Add("Major", row["Major"].ToString()); jo.Add("Fee", fee); jo.Add("Donate", donate); ja.Add(jo); feeTotal += fee; donateTotal += donate; } JObject joSummary = new JObject(); joSummary.Add("Fee", feeTotal); joSummary.Add("Donate", donateTotal); result.Add("data", ja); result.Add("summaryData", joSummary); return(Content(result.ToString(Newtonsoft.Json.Formatting.None))); }
private JObject GetSummaryData() { DataTable source = DataSourceUtil.GetDataTable2(); float donateTotal = 0.0f; float feeTotal = 0.0f; foreach (DataRow row in source.Rows) { donateTotal += Convert.ToInt32(row["Donate"]); feeTotal += Convert.ToInt32(row["Fee"]); } JObject summary = new JObject(); //summary.Add("major", "全部合计"); summary.Add("Fee", feeTotal.ToString("F2")); summary.Add("Donate", donateTotal.ToString("F2")); return(summary); }
public void ProcessRequest(HttpContext context) { //System.Threading.Thread.Sleep(2000); String term = context.Request.QueryString["term"]; if (!String.IsNullOrEmpty(term)) { term = term.ToLower(); JArray ja = new JArray(); DataTable source = DataSourceUtil.GetDataTable2(); DataTable result = source.Clone(); foreach (DataRow row in source.Rows) { string userName = row["Name"].ToString(); if (userName.Contains(term)) { JObject jo = new JObject(); jo.Add("value", userName); jo.Add("gender", Convert.ToInt32(row["Gender"])); jo.Add("entranceYear", Convert.ToInt32(row["EntranceYear"])); jo.Add("entranceDate", row["entranceDate"].ToString()); jo.Add("atSchool", Convert.ToBoolean(row["AtSchool"])); jo.Add("major", row["Major"].ToString()); ja.Add(jo); } } context.Response.ContentType = "text/plain"; context.Response.Write(ja.ToString()); } }
// GET: GridDataUrl/SortingData public ActionResult Index(string sortField, string sortDirection, bool?data2) { JArray ja = new JArray(); DataTable source = null; if (data2.HasValue && data2.Value) { source = DataSourceUtil.GetDataTable2(); } else { source = DataSourceUtil.GetDataTable(); } DataView view1 = source.DefaultView; view1.Sort = String.Format("{0} {1}", sortField, sortDirection); DataTable sortedTable = view1.ToTable(); foreach (DataRow row in sortedTable.Rows) { JObject jo = new JObject(); jo.Add("Id", (int)row["Id"]); jo.Add("Name", row["Name"].ToString()); jo.Add("Gender", (int)row["Gender"]); jo.Add("EntranceYear", (int)row["EntranceYear"]); jo.Add("AtSchool", (bool)row["AtSchool"]); jo.Add("Major", row["Major"].ToString()); jo.Add("Group", (int)row["Group"]); ja.Add(jo); } return(Content(ja.ToString(Newtonsoft.Json.Formatting.None))); }
/// <summary> /// 模拟返回总项数 /// </summary> /// <returns></returns> private int GetTotalCount() { return(DataSourceUtil.GetDataTable2().Rows.Count); }
public ActionResult btnRebindData_Click(string[] fields) { UIHelper.Grid("Grid1").DataSource(DataSourceUtil.GetDataTable2(), fields); return(UIHelper.Result()); }