项目经验之:坚决丢掉GridView ,你的数据展示才能做得更好!


 

终于放弃了微软自带的 GridView ,,数据的展示全部通过HTML + js + jQUERY 程现.

下面脚本是分页脚本 ,通过调用传入的 一般处理页面程序进行处理

 1 //首页
2 function first(pageindex,pagesize, handlepage, act,data) {
3 $.post("../handle/" + handlepage, { page: pageindex,psize:pagesize, action: act, data: data },
4 function(data) {
5 if (act.indexOf('$') == -1)
6 $("#content").html(data);
7 else
8 $("#content" + act.substr(act.indexOf('$') + 1)).html(data);
9 });
10 }
11
12 //上一页
13
14 function back(pageindex, pagecount,pagesize, handlepage, act, data) {
15 if (pageindex > 1) {
16 $.post("../handle/" + handlepage, { page: pageindex - 1,psize:pagesize, action: act, data: data },
17 function(data) {
18 if (act.indexOf('$') == -1)
19 $("#content").html(data);
20 else
21 $("#content" + act.substr(act.indexOf('$') + 1)).html(data);
22 });
23 }
24 }
25
26 //下一页
27
28 function next(pageindex, pagecount,pagesize, handlepage, act, data) {
29
30 if (pageindex + 1 <= pagecount) {
31 $.post("../handle/" + handlepage, { page: pageindex + 1,psize:pagesize, action: act, data: data },
32 function(data) {
33 if (act.indexOf('$') == -1)
34 $("#content").html(data);
35 else
36 $("#content" + act.substr(act.indexOf('$') + 1)).html(data);
37 });
38 }
39
40 }
41
42 //末页
43 function last(pageindex,pagesize, handlepage, act, data) {
44 $.post("../handle/" + handlepage, { page: pageindex,psize:pagesize, action: act,data:data },
45 function(data) {
46 if (act.indexOf('$') == -1)
47 $("#content").html(data);
48 else
49 $("#content" + act.substr(act.indexOf('$') + 1)).html(data);
50 });
51
52 }
53
54 //跳转到第几页
55 function go(pageindex, pagecount,pagesize, handlepage, act, data) {
56 if (isNaN(pageindex)) {
57 alert("请输入数字!");
58 return false;
59 }
60 if (pageindex > 0 && pageindex <= pagecount) {
61 $.post("../handle/" + handlepage, { page: pageindex,psize:pagesize, action: act,data:data},
62 function(data) {
63 if (act.indexOf('$') == -1)
64 $("#content").html(data);
65 else
66 $("#content" + act.substr(act.indexOf('$') + 1)).html(data);
67 });
68 }
69 }

后面一般处理程做了封装。。统一由request["action"]传入的参数进行处理

  1 public class FunItemHandler : IHttpHandler, IRequiresSessionState
2 {
3
4 DataRow MyRow;
5 DataColumn column = new DataColumn();
6 DataTable table = new DataTable();
7
8 int pageSize = Config.PageSize; //页记录数
9 int recordCount = 0; //记录总数
10 string orderField = "SSO_FunItem.FunItemCode asc, SSO_FunItem.Sort asc ";
11 int pageIndex = 1; //页索引
12 int pageCount = 10; //页总数
13
14 private StringBuilder strWhere = new StringBuilder();
15 string strTable = " SSO_FunItem";
16
17 HtgtIPSCommon.Base.UserInfo userInfo = null;
18
19 public void ProcessRequest (HttpContext context) {
20 context.Response.ContentType = "text/plain";
21
22 if (context.Request["action"] != null)
23 {
24 if (context.Request["psize"] != null && context.Request["psize"] != "undefined")
25 pageSize = int.Parse(context.Request["psize"]);
26 else
27 pageSize = Config.PageSize;
28 switch (context.Request["action"])
29 {
30 case "list": //不分页查询
31 QueryList(context,100);
32 break;
33 case "insert": //增加
34 ListInfo(context, 1);
35 break;
36 case "update": //修改
37 ListInfo(context, 2);
38 break;
39 case "delete": //删除
40 ListInfo(context, 3);
41 break;
42 case "listPage": //分页查询
43 QueryList(context, pageSize);
44 break;
45 default:
46 break;
47 }
48
49 }
50 }
51 /// <summary>
52 /// 查询数据
53 /// </summary>
54 /// <param name="pageSize"></param>
55 public void QueryList(HttpContext context, int pageSize)
56 {
57 FunItemBll funItembll = new FunItemBll();
58 strWhere.Append(" 1=1");
59 pageIndex = context.Request["page"] == null ? 1 : int.Parse(context.Request["page"]);
60
61 //执行反序列化
62 JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
63 FunItemModel data = jsonSerializer.Deserialize<FunItemModel>(context.Request["data"]);
64 if (!string.IsNullOrEmpty(data.Condition))
65 {
66 strWhere.Append(" and "+ data.Condition.Split('$')[0] +" like '%" + data.Condition.Split('$')[1] + "%'");
67 }
68
69 //System.Data.DataSet ds_FunItem = funItembll.Query_Sql(strWhere.ToString(), strTable, pageSize, pageIndex, out recordCount, orderField);
70
71 DataTable dt = funItembll.FunItemTable(strWhere.ToString(), pageIndex, pageSize, out recordCount);
72 System.Data.DataSet ds_FunItem = new DataSet();
73 ds_FunItem.Tables.Add(dt);
74 if (recordCount % pageSize > 0)
75 {
76 pageCount = recordCount / pageSize + 1;
77 }
78 else
79 {
80 pageCount = recordCount / pageSize;
81 }
82 AutoGrid.Common.AutoGrid grid = new AutoGrid.Common.AutoGrid();
83 grid.PkField = "FunItemCode";
84 grid.FieldName = "FunItemCode,FunName,WebURL,SearchCondition";
85 grid.FieldText = "菜单编码,名称,地址,快捷搜索条件";
86 grid.ColumnWidth = "";
87 grid.TableStyle = "tableList"; //样式
88 grid.IsCheckBox = true;
89
90 string html = grid.PrintWebList(ds_FunItem, recordCount, pageIndex, pageCount, pageSize, "FunItemHandler.ashx", "listPage", HttpUtility.HtmlEncode(context.Request["data"]));
91
92 context.Response.Write(html);
93 }
94 /// <summary>
95 /// 增加,修改,删除操作
96 /// </summary>
97 /// <param name="context"></param>
98 /// <param name="pageSize"></param>
99 public void ListInfo(HttpContext context, int flag)
100 {
101 //执行反序列化
102 JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
103 FunItemModel data = jsonSerializer.Deserialize<FunItemModel>(context.Request["data"]);
104 BaseBLL<FunItemModel, FunItemDal> bll = new BaseBLL<FunItemModel, FunItemDal>();
105 FunItemModel model = null;
106 FunItemBll funItemBll = null;
107
108 userInfo = (UserInfo)context.Session["userInfo"];
109 if (flag == 1) //增加
110 {
111 model = new FunItemModel();
112 funItemBll = new FunItemBll();
113 if (bll.Exists(" FunItemCode='" + data.FunItemCode + "'"))
114 {
115 context.Response.Write("0");
116 return;
117 }
118 model.FID = funItemBll.GetSeedID("SSO_FunItem"); //分配FID
119 model.FunItemCode = data.FunItemCode;
120 model.FunName = data.FunName;
121 model.FunTitle = data.FunTitle;
122 model.ParentID = data.ParentID;
123 if (data.ParentID == 0)
124 {
125 model.ParentIDPath = "0";
126 model.FunLevel = 1;
127 }
128 else {
129 model.ParentIDPath = "0," + model.ParentID;
130 model.FunLevel = model.ParentIDPath.Split(',').Length;
131 }
132 model.FunICO = data.FunICO; //菜单图标
133 model.WebURL = data.WebURL;
134 model.IsAppURL = data.IsAppURL;
135 model.IsUse = data.IsUse;
136 model.Target = data.Target;
137 model.Sort = data.Sort;
138 model.SearchCondition = data.SearchCondition;
139
140 model.FCUser = data.FCUser; //这一块从Session中取
141 model.FCDate = DateTime.Now;
142
143 List<ActionBtnModel> listItems = null;
144
145 if (data.Condition != "")
146 {
147 listItems = new List<ActionBtnModel>();
148 //获取按钮对象集
149 string[] items = data.Condition.Split(',');
150 foreach (string item in items)
151 {
152 if (item != "")
153 {
154 ActionBtnModel actionBtnModel = new ActionBtnModel();
155 string[] temp = item.Split('$');
156 actionBtnModel.BtnType = temp[0].ToString();
157 actionBtnModel.BtnICO = temp[1].ToString();
158 actionBtnModel.BtnName = temp[2].ToString();
159 actionBtnModel.BtnID = temp[3].ToString().Trim();
160 actionBtnModel.BtnMain = temp[4].ToString();
161
162 actionBtnModel.FunItemUrl = data.WebURL;
163 actionBtnModel.FunItemCode = data.FunItemCode;
164 listItems.Add(actionBtnModel);
165 }
166 }
167 }
168
169
170 model.ListActionBtn = listItems;
171 int count = bll.Insert(model);
172 if (count > 0)
173 context.Response.Write("1"); //成功
174 else
175 context.Response.Write(null);
176 }
177 else if (flag == 2) //修改
178 {
179
180 model = new FunItemModel();
181 funItemBll = new FunItemBll();
182 model = funItemBll.GetModel(data.FunItemCode);
183
184 model.FunName = data.FunName;
185 model.FunTitle = data.FunTitle;
186 model.ParentID = data.ParentID;
187 if (data.ParentID == 0)
188 {
189 model.ParentIDPath = "0";
190 model.FunLevel = 1;
191 }
192 else
193 {
194 model.ParentIDPath = "0," + model.ParentID;
195 model.FunLevel = model.ParentIDPath.Split(',').Length;
196 }
197 model.WebURL = data.WebURL;
198 model.IsAppURL = data.IsAppURL;
199 model.IsUse = data.IsUse;
200 model.Target = data.Target;
201 model.Sort = data.Sort;
202 model.SearchCondition = data.SearchCondition;
203
204 model.FEUser = data.FEUser; //这一块从Session中取
205 model.FEDate = DateTime.Now;
206
207 List<ActionBtnModel> listItems = null;
208
209 if (data.Condition != "")
210 {
211 listItems = new List<ActionBtnModel>();
212 //获取按钮对象集
213 string[] items = data.Condition.Split(',');
214 foreach (string item in items)
215 {
216 if (item != "")
217 {
218 ActionBtnModel actionBtnModel = new ActionBtnModel();
219 string[] temp = item.Split('$');
220 actionBtnModel.BtnType = temp[0].ToString();
221 actionBtnModel.BtnICO = temp[1].ToString();
222 actionBtnModel.BtnName = temp[2].ToString();
223 actionBtnModel.BtnID = temp[3].ToString().Trim();
224 actionBtnModel.BtnMain = temp[4].ToString();
225
226 actionBtnModel.FunItemUrl = data.WebURL;
227 actionBtnModel.FunItemCode = data.FunItemCode;
228 listItems.Add(actionBtnModel);
229 }
230 }
231 }
232 model.ListActionBtn = listItems;
233
234 int count = bll.Update(model);
235 if (count > 0)
236 context.Response.Write("2"); //成功
237 else
238 context.Response.Write(null);
239 }
240 else if (flag == 3) //删除
241 {
242 int count = bll.Delete(data.FID);
243 if (count > 0)
244 context.Response.Write("1"); //成功
245 else
246 context.Response.Write(null);
247 }


 

  1 function funBtnSelect()
2 {
3 var ajaxManage = new AjaxManage();
4 var obj = new Object();
5 var id = GetQueryString("fid");
6 var data = {
7 FID: id
8 }
9 obj.url = "FunItemHandler";
10 obj.page = "1";
11 obj.data = data;
12 obj.action = "listPage"
13
14 obj.SuccessCallFunc = function (data) {
15 if (data != null) {
16 $("#content").html(data)
17 }
18 };
19 obj.BeforeSendCallFunc = function () {
20 $("#content").html("读数据加载中...");
21 };
22 obj.CompleteCallFunc = function () {
23 };
24 ajaxManage.QAjax(obj);
25 }
26
27 $(function(){
28 var ajaxManage = new AjaxManage();
29 var obj = new Object();
30 var id = GetQueryString("fid");
31 var data = {
32 FID: id
33 }
34 obj.url = "FunItemHandler";
35 obj.page = "1";
36 obj.data = data;
37 obj.action = "listPage"
38
39 obj.SuccessCallFunc = function (data) {
40 if (data != null) {
41 $("#content").html(data)
42 }
43 };
44 obj.BeforeSendCallFunc = function () {
45 $("#content").html("读数据加载中...");
46 };
47 obj.CompleteCallFunc = function () {
48 };
49 ajaxManage.QAjax(obj);
50 })
51 function funBtnInsert()
52 {
53 window.location.href="FunItemInfo.aspx";
54 }
55 function funBtnUpdate()
56 {
57 var ids = [];
58 $(":input[name='checkbox']:checked").each(function () {
59 ids.push($(this).val());
60 })
61 var checkInfo = "";
62 if (ids.length == 1 ) {
63 checkInfo = ids[0];
64 window.location.href="FunItemInfo.aspx?fid="+checkInfo;
65 }
66 else if(ids.length==0){
67 $.messager.alert('提示', '请选择一条记录进行操作!', 'info');
68 return;
69 }
70 else if(ids.length>1){
71 $.messager.alert('提示', '您选择了多条记录,只能选择一条记录进行修改!', 'info');
72 return;
73 }
74 }
75 function funBtnDelete()
76 {
77 var ids = [];
78 $(":input[name='checkbox']:checked").each(function () {
79 ids.push($(this).val());
80 })
81 if(ids.length==0){
82 $.messager.alert('提示', '请选择一条记录进行操作!', 'info');
83 return;
84 }
85 else if(ids.length>1){
86 $.messager.alert('提示', '您选择了多条记录,只能选择一条记录进行删除!', 'info');
87 return;
88 }
89 else if(ids.length == 1 ){
90 $.messager.confirm('提示信息', '您确认要删除吗?', function (data) {
91 if(data)
92 {
93 var ajaxManage = new AjaxManage();
94 var obj = new Object();
95 var id = GetQueryString("fid");
96 var data = {
97 FID: ids[0]
98 }
99 obj.url = "FunItemHandler";
100 obj.page = "1";
101 obj.data = data;
102 obj.action = "delete"
103
104 obj.SuccessCallFunc = function (data) {
105 if (data != null) {
106 if(data==1)
107 {
108 $.messager.alert('提示', '数据操作成功!', 'info');
109 funBtnSelect();
110 }
111 }
112 };
113 obj.BeforeSendCallFunc = function () {
114 $("#content").html("读数据加载中...");
115 };
116 obj.CompleteCallFunc = function () {
117 };
118 ajaxManage.QAjax(obj);
119 }
120 });
121 }
122 }

 


 

posted @ 2012-02-17 14:53  GIS发展  阅读(5587)  评论(49编辑  收藏  举报