博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Repeater + Resources 列表 [原创][分享]
阅读量:5105 次
发布时间:2019-06-13

本文共 13247 字,大约阅读时间需要 44 分钟。

根据公司的业务要求写了一个列表控件,大致实现以下功能(大体思路实现)
1、数据绑定(可根据设置显示隐藏列表字段)
2、根据resources文件设置列表头
3、排序,分页
4、列表的筛选功能
主体代码:
前台页面设置控件代码
<
div id
=
"
listTitle
"
 style
=
"
width: 100%
"
 
class
=
"
bgblue
"
>
                        
<
ul
>
                            
<
li style
=
"
width: 30px; text-align: center; float: left;
"
 
class
=
"
bgblue
"
>
选择
</
li
>
                            
<
asp:Label ID
=
"
c1
"
 runat
=
"
server
"
 
></
asp:Label
>
                            
<
asp:Label ID
=
"
c2
"
 runat
=
"
server
"
 
></
asp:Label
>
                            
<
asp:Label ID
=
"
c3
"
 runat
=
"
server
"
 
></
asp:Label
>
                            
<
asp:Label ID
=
"
c4
"
 runat
=
"
server
"
 
></
asp:Label
>
                            
<
asp:Label ID
=
"
c5
"
 runat
=
"
server
"
 
></
asp:Label
>
                            
<
asp:Label ID
=
"
c6
"
 runat
=
"
server
"
 
></
asp:Label
>
                            
<
asp:Label ID
=
"
c7
"
 runat
=
"
server
"
 
></
asp:Label
>
                            
<
asp:Label ID
=
"
c8
"
 runat
=
"
server
"
 
></
asp:Label
>
                            
<
asp:Label ID
=
"
c9
"
 runat
=
"
server
"
 
></
asp:Label
>
                            
<
asp:Label ID
=
"
c10
"
 runat
=
"
server
"
 
></
asp:Label
>
                        
</
ul
>
                    
</
div
>
                    
<
div id
=
"
joblist
"
>
                        
<
asp:Repeater ID
=
"
resume
"
 runat
=
"
server
"
>
                            
<
ItemTemplate
>
                                
<
div style
=
"
width: 100%
"
 
class
=
"
navlist
"
 id
=
'
<%# DataBinder.Eval(Container.DataItem, "ResumeID") %>
'
>
                                    
<
ul
>
                                        
<
li style
=
"
width: 30px; text-align: center; float: left;
"
>
                                            
<
input type
=
"
checkbox
"
 name
=
"
checkbox
"
 style
=
"
cursor: hand
"
 value
=
"
<%# DataBinder.Eval(Container.DataItem, 
"
id
"
) %>
"
                                                keyid
=
'
<%# DataBinder.Eval(Container.DataItem, "id") %>
'
 url
=
'
<%# DataBinder.Eval(Container.DataItem, "url") %>
'"
'>
                                        
</
li
>
                                        
<
asp:Label ID
=
"
column1
"
 runat
=
"
server
"
 
></
asp:Label
>
                                        
<
asp:Label ID
=
"
column2
"
 runat
=
"
server
"
 
></
asp:Label
>
                                        
<
asp:Label ID
=
"
column3
"
 runat
=
"
server
"
 
></
asp:Label
>
                                        
<
asp:Label ID
=
"
column4
"
 runat
=
"
server
"
 
></
asp:Label
>
                                        
<
asp:Label ID
=
"
column5
"
 runat
=
"
server
"
 
></
asp:Label
>
                                        
<
asp:Label ID
=
"
column6
"
 runat
=
"
server
"
 
></
asp:Label
>
                                        
<
asp:Label ID
=
"
column7
"
 runat
=
"
server
"
 
></
asp:Label
>
                                        
<
asp:Label ID
=
"
column8
"
 runat
=
"
server
"
 
></
asp:Label
>
                                        
<
asp:Label ID
=
"
column9
"
 runat
=
"
server
"
 
></
asp:Label
>
                                        
<
asp:Label ID
=
"
column10
"
 runat
=
"
server
"
 
></
asp:Label
>
                                    
</
ul
>
                                
</
div
>
                            
</
ItemTemplate
>
                        
</
asp:Repeater
>
                    
</
div
>
后台代码实现:
  1
using
 System;
  2
using
 System.Collections;
  3
using
 System.Configuration;
  4
using
 System.Data;
  5
using
 System.Linq;
  6
using
 System.Web;
  7
using
 System.Web.Security;
  8
using
 System.Web.UI;
  9
using
 System.Web.UI.HtmlControls;
 10
using
 System.Web.UI.WebControls;
 11
using
 System.Web.UI.WebControls.WebParts;
 12
using
 System.Xml.Linq;
 13
 14
using
 System.Text;
 15
using
 System.Reflection;
 16
using
 System.Collections.Generic;
 17
using
 System.Resources;
 18
 19
public
 
partial
 
class
 _Receive : PageBase
 20
{
 21    /**//// <summary>
 22    /// 初始默认值(显示列的字段)(数组)
 23    /// </summary>
 24    private string[] columns = new string[] 
 25        "IsSee",//是否查看  +1
 26        "JobSeekerName",//求职者姓名    +2
 27        "Jobname",//职位名称     +3
 28        "WorkYear",//工作年限  +4
 29        "NowCityCodevalue",//所在地址 +5
 30        "Degreevalue",//学历    +6
 31        "CreateDate",//创建日期 +7
 32        "SystemLeach",//系统过滤
 33        "Assess",//简历评估
 34        "Photo"//相片
 35    }
;
 36
 37    private string[] CheckedRequestString = new string[]{
 38        "JOBId",//职位id
 39        "pjno",//折叠
 40        "menuid",//套红
 41        "positionid",//职位夹id
 42        "summarystyleid",//列表显示样式
 43        "workyear",//工作年限
 44        "address",//地址
 45        "degree",//学历
 46        "tradeid",//行业id
 47        "job",//岗位id
 48        "sex",//性别
 49        "vocationalid",//专业
 50        "time",//日期
 51        "wy",
 52        "szdz",
 53        "xl"
 54    }
;
 55
 56    /**//// <summary>
 57    /// 初始默认值(显示列的字段)
 58    /// </summary>
 59    private string seachShowColumns = PageBase.GetDefaultColumnCode(PageBase.PageTableNo.Receive.ToString());
 60
 61    /**//// <summary>
 62    /// 初始排序字段
 63    /// </summary>
 64    private string sortColumn = "CreateDate";
 65    /**//// <summary>
 66    /// 初始排序的方式
 67    /// </summary>
 68    private string sortDirection = "ASC";
 69
 70    protected void Page_Load(object sender, EventArgs e)
 71    {
 72        if (!this.IsPostBack)
 73        {
 74            this.ddlDatabind();
 75            this.InitColumns();
 76            this.GetReceiveDatabind();
 77
 78            /**////
 79            this.txtwork.Value = System.DateTime.Now.ToString("yyyy-MM-dd");
 80            /**////
 81        }
 82    }
 83    数据列表加载#region 数据列表加载
 84
 85    /**//// <summary>
 86    /// pageload的时候加载列表头
 87    /// </summary>
 88    private void InitColumns(){
 89        PageTableProfileBAL ptpb;
 90        PageTableProfileBAL.GetInstance(out ptpb);
 91        List<PageTableProfile> ptp = ptpb.GetPageTableProfileByColmn(UserID, PageBase.PageTableNo.Receive.ToString());
 92        
 93        string keycontent = ptp.Count == 1 && ptp[0].SeachShowColumns != "" ? ptp[0].SeachShowColumns : this.SeachShowColumns;
 94        
 95        //string CheckedColumnReplace = "SendStatus,IsSee,IsFavOrBuy,";
 96        //if (keycontent.IndexOf(CheckedColumnReplace) == -1)
 97        //    keycontent = CheckedColumnReplace + keycontent;
 98
 99        /**////modfiy by john on 2008-05-24 
100        ///加上需要显示的图片信息。 定义当前的图片以及还原位置.
101        string CheckedColumnReplace = "IsSee,SystemLeach,Assess,Photo,";
102        if (keycontent.IndexOf(CheckedColumnReplace) == -1)
103            keycontent = CheckedColumnReplace + keycontent;
104
105        string keycontentcopyto = "";
106
107        foreach (string defaultcolumnkey in this.columns)
108        {
109            if (keycontent.IndexOf(defaultcolumnkey) > -1)
110            {
111                keycontentcopyto += defaultcolumnkey + ",";
112            }
113        }
114        keycontent = keycontentcopyto.TrimEnd(',');
115
116        columns = ResizeColumns(keycontent.Split(",".ToCharArray()));
117        string virtualPath = Page.Request.ApplicationPath + "/Receive.aspx";
118
119        for (int i = 0; i < columns.Length; i++)
120        {
121            ContentPlaceHolder cp = (ContentPlaceHolder)Master.FindControl("content_plane");
122            Label label = cp.FindControl("c" + (i + 1)) as Label;
123            label.Text = CreateHeaderColumn(GetColumnText(virtualPath, columns[i]), columns[i]);
124        }
125    }
126
127    /**//// <summary>
128    /// 获得列表显示字段的描述
129    /// </summary>
130    /// <param name="virtualPath"></param>
131    /// <param name="columnName"></param>
132    /// <returns></returns>
133    private string GetColumnText(string virtualPath, string columnName)
134    {
135        /**////modify john at 2008-05-29 
136        ///手动识别资源文字
137        return HttpContext.GetLocalResourceObject(virtualPath, "Column_" + columnName).ToString() == "创建时间" ? "更新日期" : HttpContext.GetLocalResourceObject(virtualPath, "Column_" + columnName).ToString();
138    }
139
140    /**//// <summary>
141    /// 创建列表头部
142    /// </summary>
143    /// <param name="text"></param>
144    /// <param name="columnName"></param>
145    /// <returns></returns>
146    private string CreateHeaderColumn(string text, string columnName)
147    {
148        StringBuilder sb = new StringBuilder();
149
150        if (columnName == "SystemLeach" || columnName == "IsSee" || columnName == "Assess" || columnName == "Photo")   /**////图标的特殊形式处理
151        {
152            sb.AppendFormat("<li style=\"width:16px;text-align: center;float: left;\" class=\"bgblue\">");
153            sb.Append("</li>");
154        }
155        else
156        {
157            
158            /**////标签标准形式的处理
159            sb.AppendFormat("<li style=\"width:{
0}
px;text-align: center;float: left;\" class=\"bgblue\">", GetColumnWidth(columnName, this.columns.Length));
160            sb.AppendFormat("<img src=\"{
0}
\" width=\"7\" height=\"4\" hspace=\"4\" border=\"0\" align=\"absmiddle\"/>", GetSortImageName(columnName));
161            sb.AppendFormat("<a href='#' class='dark2' id='{1}' οnclick=tableSort(this,'{2}')>{0}</a>", text, columnName, this.sortDirection);
162            sb.Append("</li>");
163            break;
164            
165        }
166        return sb.ToString();
167    }
168
169
170    /**//// <summary>
171    /// 排序显示相对应的image
172    /// </summary>
173    /// <param name="columnName"></param>
174    /// <returns></returns>
175    private string GetSortImageName(string columnName)
176    {
177        if (this.sortColumn == columnName)
178        {
179            if (this.sortDirection == "ASC")
180            {
181                //return "jian.gif";
182                return "http://xxxxx/App_Themes/default/jobseekers/images/desc.gif";
183            }
184            else
185            {
186                //return "up.gif";
187                return "http://xxxxxx/App_Themes/default/jobseekers/images/asc.gif";
188            }
189        }
190        else
191        {
192            return "http://xxxxxx/App_Themes/default/jobseekers/images/up.gif";
193        }
194    }
195
196    /**//// <summary>
197    /// 得到需要显示的列的个数
198    /// </summary>
199    /// <param name="columns"></param>
200    /// <returns></returns>
201    private string[] ResizeColumns(string[] columns)
202    {
203        string[] cc = null;
204        if (columns.Length > 11)
205        {
206            cc = new string[11];
207            for (int i = 0; i < 11; i++)
208            {
209                cc[i] = columns[i];
210            }
211        }
212        else
213        {
214            cc = columns;
215        }
216        return cc;
217    }
218
219    /**//// <summary>
220    /// 得到列表与头部标签的宽度
221    /// </summary>
222    /// <param name="columnName"></param>
223    /// <param name="columnCount"></param>
224    /// <returns></returns>
225    private string GetColumnWidth(string columnName, int columnCount)
226    {
227        int tablewidth = 705,width = 0,length = this.columns.Length-4;tablewidth = 705 - (16 * 4- 30;
228        width = tablewidth / length;
229        return width.ToString();
230    }
231
232    /**//// <summary>
233    /// 数据访问,绑定列表集
234    /// </summary>
235    public void GetReceiveDatabind()
236    {
237        FavoriteBAL frb;
238        FavoriteBAL.GetInstance(out frb);
239        List<Favorite> fr = new List<Favorite>();
240        
241        sortColumn = this.__sortorder.Value;
242        sortColumn = sortColumn == string.Empty ? "CompanyID" : sortColumn;
243        string orderdesc = sortColumn + " " + sortDirection;
244
245        this.pager1.PageUrl = CheckedRequest();
246
247        int RecordCount = 0;
248        pager1.PageSize = getPageSize() == 0 ? 20 : getPageSize();
249        fr = frb.GetFavoriteSequence(search() + searchkey() , pager1.CurrentPageIndex,orderdesc, trueref RecordCount, pager1.PageSize, true,false);
250
251        pager1.RecordCount = RecordCount;
252        this..DataSource = fr;
253        this..ItemDataBound += new RepeaterItemEventHandler(_ItemDataBound);
254        this..DataBind();
255    }
256
257    protected int getPageSize()
258    {
259        PageTableProfileBAL ptpb;
260        PageTableProfileBAL.GetInstance(out ptpb);
261        List<PageTableProfile> ptp = ptpb.GetPageTableProfileByColmn(UserID, PageBase.PageTableNo.Receive.ToString());
262        int pagesizeinit = 0;
263        if (ptp.Count == 1)
264            pagesizeinit = ptp[0].SearchResultPageSize;
265        return pagesizeinit;
266    }
267
268    /**//// <summary>
269    /// 循环读取设置列表值
270    /// </summary>
271    /// <param name="sender"></param>
272    /// <param name="e"></param>
273    void _ItemDataBound(object sender, RepeaterItemEventArgs e)
274    {
275        RepeaterItem item = e.Item;
276        Favorite fr = item.DataItem as Favorite;
277        for (int i = 0; i < columns.Length; i++)
278        {
279            Label label1 = item.FindControl("column" + (i + 1)) as Label;
280            label1.Text = GetValue(fr, i);
281        }
282    }
283
284    /**//// <summary>
285    /// 获得列表显示相应的字段值
286    /// </summary>
287    /// <param name="fr"></param>
288    /// <param name="index"></param>
289    /// <returns></returns>
290    private string GetValue(Favorite fr, int index)
291    {
292        if (index > columns.Length || index == -1return "";
293        PropertyInfo info = fr.GetType().GetProperty(columns[index].ToString());
294        string text = string.Empty;
295        if (info.GetValue(fr, null!= null)
296        {
297            text = info.GetValue(fr, null).ToString();
298        }
299        StringBuilder sb = new StringBuilder();
300
301        if (columns[index].Equals("SystemLeach"|| columns[index].Equals("IsSee"|| columns[index].Equals("Assess"|| columns[index].Equals("Photo"))
302        {
303            sb.AppendFormat("<li style=\"width:16px;text-align: center;float: left;\">");//class=\"" + columns[index] + "\"
304            switch (columns[index])
305            {
306                case "SystemLeach":
307                    sb.AppendFormat("{0}""<img src=\"http://xxx/v5/images/03525520.gif\" width=\"16\" height=\"16\" />");
308                    break;
309                case "IsSee":
310                    sb.AppendFormat("{0}""<img src=\"http://xxx/v5/images/17_03.gif\" width=\"16\" height=\"16\" />");
311                    break;
312                case "Assess":
313                    sb.AppendFormat("{0}""<img src=\"http://xxx/v5/images/17_01.gif\" width=\"16\" height=\"16\" />");
314                    break;
315                case "Photo":
316                    sb.AppendFormat("{0}""<img src=\"http://xxx/v5/images/17_04.gif\" width=\"16\" height=\"16\" />");
317                    break;
318            }
319            
320            sb.Append("</li>");
321        }
322        else
323        {
324            sb.AppendFormat("<li style=\"width:{
0}
px;text-align: center;float: left; overflow:hidden;'>\">", GetColumnWidth(columns[index], this.columns.Length));//class=\"" + columns[index] + "\"
325            if (columns[index].Equals("CreateDate"))
326                text = Convert.ToDateTime(text).ToString("yyyy-MM-dd");
327            if (columns[index].Equals("WorkYear"))
328            {
329                if (text == "0")
330                    text = "应届毕业";
331                else
332                    text += "";
333            }
334            sb.AppendFormat("{0}", text);
335            sb.Append("</li>");
336        }
337        return sb.ToString();
338    }
339    #endregion
340
341    设置需要查询的条件#region 设置需要查询的条件
342
343    private string search()
344    {
345        return "delstatus != " + (int)PageBase.DelStatus.Yes + " and status = " + (int)PageBase.Status.Receive + " and userid = '" + UserID + "'";
346    }
347
348
349   
350    #endregion
351
352    
353
354    自定义属性#region 自定义属性
355
356    private List<Favorite> FavoriteTable
357    {
358        get
359        {
360            return ViewState["FavoriteTable"as List<Favorite>;
361        }
362        set
363        {
364            ViewState["FavoriteTable"= value;
365        }
366    }
367
368    public string SeachShowColumns
369    {
370        get return this.seachShowColumns; }
371
372        set
373        {
374            if (!string.IsNullOrEmpty(value))
375            {
376                this.seachShowColumns = value;
377            }
378        }
379    }
380    protected void btnsort_Click(object sender, EventArgs e)
381    {
382        sortColumn = this.__sortorder.Value;
383        sortDirection = this.__sortDir.Value;
384
385        this.InitColumns();
386        this.GetReceiveDatabind();
387    }
388
389    #endregion
390}
391

转载于:https://www.cnblogs.com/zjx-sir/archive/2008/07/09/1239047.html

你可能感兴趣的文章
如何在Access2007中使用日期类型查询数据
查看>>
Jzoj4757 树上摩托
查看>>
CF992E Nastya and King-Shamans(线段树二分+思维)
查看>>
基于docker的spark-hadoop分布式集群之一: 环境搭建
查看>>
oracle 几个时间函数探究
查看>>
第一个Java Web程序
查看>>
Atomic
查看>>
div 显示滚动条与div显示隐藏的CSS代码
查看>>
Redis-1-安装
查看>>
Access denied for user ''@'localhost' to database 'mysql'
查看>>
微信公众号里面使用地图导航
查看>>
部署支持 https 的 Nginx 服务
查看>>
‘Cordova/CDVPlugin.h’ file not found
查看>>
WebAssembly是什么?
查看>>
C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件)...
查看>>
树状数组_一维
查看>>
【拓扑排序】【最短路】【最小生成树】Day 9.2
查看>>
如果没有按照正常的先装iis后装.net的顺序,可以使用此命令重新注册一下:
查看>>
linux install ftp server
查看>>
C# 使用 Abot 实现 爬虫 抓取网页信息 源码下载
查看>>