html:
1 <div id="datagrid1" class="mini-datagrid" style="width:725px;height:250px;" 2 url="Default.aspx?method=SearchProducts" 3 idField="ID" 4 multiSelect="true" allowResize="true" > 5 6 <!-- <div id="datagrid1" class="mini-datagrid" style="width:725px;height:250px;" 7 url="t1.txt" idField="ID" 8 multiSelect="true" allowResize="true" >--> 9 10 <div property="columns"> 11 <div type="checkcolumn"></div> 12 <div field="Text" width="120" allowSort="true">产品名称</div> 13 <div field="Area" width="100" allowSort="true">地区</div> 14 <div field="Amount" width="100" allowSort="true">金额</div> 15 <div field="PointNo" width="100" allowSort="true">MYCARD</div> 16 <div field="Tiem" width="100" dateFormat="yyyy-MM-dd" allowSort="true">修改日期</div> 17 18 </div> 19 </div> 20 21 <script type="text/javascript"> 22 mini.parse(); 23 var grid = mini.get("datagrid1"); 24 grid.load(); 25 </script>
用url指向txt文件可以显示,但是指向服务端的方法,断点调试跟踪都可以正确执行,而且可以返回可用的json数据
数据如下:
{"total":2, "data":[ {"Area":"1", "ID":"201207181717064687", "PointNo":"400點", "Units":"元", "Time":"2012-07-18T17:17:36", "VersionType":"", "Text":"一個遊戲帳號30天", "IbonPrice":"", "Name":null, "NetCardpoint":"點", "Amount":"250", "AreaName":"台灣" }, {"Area":"1", "ID":"201207181717277187", "PointNo":"800點", "Units":"元", "Time":"2012-07-18T17:17:27", "VersionType":"", "Text":"一個遊戲帳號90天", "IbonPrice":"", "Name":null, "NetCardpoint":"點", "Amount":"500", "AreaName":"台灣" } ]}
服务端代码:
1 public partial class _Default : System.Web.UI.Page 2 { 3 protected void Page_Load(object sender, EventArgs e) 4 { 5 String methodName = Request["method"]; 6 Type type = this.GetType(); 7 MethodInfo method = type.GetMethod(methodName); 8 if (method == null) throw new Exception("method is null"); 9 10 method.Invoke(this, null); 11 } 12 13 public void SearchProducts() 14 { 15 //查询条件 16 string key = Request["key"]; 17 //分页 18 int pageIndex = Convert.ToInt32(Request["pageIndex"]); 19 int pageSize = Convert.ToInt32(Request["pageSize"]); 20 //字段排序 21 String sortField = Request["sortField"]; 22 String sortOrder = Request["sortOrder"]; 23 //业务层:数据库操作 24 Hashtable result = new TestDB().SearchProducts(key, pageIndex, pageSize, sortField, sortOrder); 25 //JSON 26 String json = PluSoft.Utils.JSON.Encode(result); 27 //return json; 28 Response.Write(json); 29 } 30 }
执行完上面的 Response.Write(json);就完成了,数据也正确,datagrid啥也不显示。
1 public class TestDB 2 { 3 public Hashtable SearchProducts(string key, int index, int size, string sortField, string sortOrder) 4 { 5 ArrayList dataAll = new ArrayList(); 6 //执行查询 7 //载入xml文件 8 //创建HashTable 9 System.Data.DataSet ds = new System.Data.DataSet(); 10 ds.ReadXml(System.Web.HttpContext.Current.Request.MapPath("ProductType.XML")); 11 12 System.Data.DataTable dt = ds.Tables[0]; 13 14 dataAll = DataTable2ArrayList(dt); 15 16 //实现一个内存分页(实际应该使用SQL分页) 17 //分页要获取的数据 18 ArrayList data = new ArrayList(); 19 //index 页索引,size页大小,start:开始的记录索引,end接收方的记录索引。 20 int start = index * size, end = start + size; 21 22 //dataAll为返回的记录总数 23 for (int i = 0, l = dataAll.Count; i < l; i++) 24 { 25 Hashtable record = (Hashtable)dataAll[i]; 26 27 if (record == null) continue; 28 //在要获取的记录范围之间 29 if (start <= i && i < end) 30 { 31 data.Add(record);//这边将我们需要的数据加进来 32 } 33 } 34 35 Hashtable result = new Hashtable(); 36 result["data"] = data; 37 result["total"] = dataAll.Count; 38 39 return result; 40 } 41 42 #region 将DataTable转换为ArrayList 43 private static ArrayList DataTable2ArrayList(System.Data.DataTable data) 44 { 45 ArrayList array = new ArrayList(); 46 for (int i = 0; i < data.Rows.Count; i++) 47 { 48 System.Data.DataRow row = data.Rows[i]; 49 50 Hashtable record = new Hashtable(); 51 for (int j = 0; j < data.Columns.Count; j++) 52 { 53 object cellValue = row[j]; 54 if (cellValue.GetType() == typeof(DBNull)) 55 { 56 cellValue = null; 57 } 58 record[data.Columns[j].ColumnName] = cellValue; 59 } 60 array.Add(record); 61 } 62 return array; 63 } 64 #endregion 65 }
求解,调试两三天了,还是找不出哪出问题了,哪位大侠帮帮忙。
你得问Miniui的作者去。
有问了,还是没能解决。
终于可以了
Default.aspx客户端页面代码问题。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
只需这句话就可以。