利用Ilist显示记录的方法

 学海无涯,每天都会有新的发现,希望每天都能充实自己。
以前都是利用datagrid控件绑定数据并且分页,但最近看了一段别人写的代码,又学了不少新的知识

当然,以下代码是从程序里摘出来的,仅供参考
  1. //去掉了大量不必要的代码
  2. public IList list=null;
  3. public IList dislist = new ArrayList();
  4.         #region 帮顶表格
  5.         /// <summary>
  6.         /// 帮顶表格
  7.         /// </summary>
  8.         public void BindData()
  9.         {
  10.             GetDownloadList("","");
  11.             if(null!=dislist)dislist.Clear();
  12.             int start =(CurrIndex-1)*PageSize+1;
  13.             for(int i=start;i<=CurrIndex*PageSize && i<=list.Count;i++)
  14.             {
  15.                 TblDownload tbldown = (TblDownload)list[i-1];
  16.                 dislist.Add(tbldown);
  17.             }
  18.         
  19.         }
  20.         #endregion
  21.         
  22.         public void GetDownloadList(string region,string popedom)
  23.         {
  24.             Download downloads=new Download();
  25.             TblDownload tblDownload=new TblDownload();
  26.             //tblDownload.Category="COMMUNION";
  27.             tblDownload.Region = downloads.GetAgtRegion(strAgentID);
  28.             if(tblDownload.Region =="S1")   //总部地区
  29.                 tblDownload.Region = "TJ";  //总部
  30.             strAgentType  = promoteStandard.GetPromoteType(strAgentLevel);
  31.             tblDownload.Popedom=strAgentType;
  32.             list=downloads.GetTop5FileList(tblDownload);
  33.             Rectotal=list.Count;
  34.         }
  1.         /// <summary>
  2.         /// 说明:下载文件
  3.         /// </summary>
  4.         /// <param name="tblDownload">下载对象</param>
  5.         /// <returns>
  6.         /// 返回文件列表
  7.         /// </returns>
  8.         public IList GetTop5FileList(TblDownload tblDownload)
  9.         {
  10.             IList list = new ArrayList();
  11.             string SqlString = "select top 5 * from tblDownLoad where filepath <> '0' order by tblDownload.fileId desc";
  12.             SqlConnection connection = new SqlConnection( ConfigurationGlobals.ConnectionSqlString);
  13.             SqlCommand command = new SqlCommand(SqlString,connection);
  14.             SqlDataReader reader = null;
  15.             try
  16.             {
  17.                 connection.Open();
  18.                 reader = command.ExecuteReader(CommandBehavior.CloseConnection);
  19.                 while(reader.Read())
  20.                 {
  21.                     TblDownload tbldownload = TblDownload.GetModel( reader );
  22.                     list.Add(tbldownload);
  23.                 }
  24.             }
  25.             catch(Exception e)
  26.             {
  27.                 throw new DataAccessException(e.Message);
  28.             }
  29.             finally
  30.             {
  31.                 if(reader != null)
  32.                     reader.Close();
  33.             }
  34.             return list;
  35.         }
  36.         #endregion 
前台的代码
  1.                                     <table height="44" cellSpacing="0" cellPadding="0" width="760" border="0">
  2.                                         <tr>
  3.                                             <td width="239">
  4.                                                 <table height="22" cellSpacing="0" cellPadding="0" width="752" border="0">
  5.                                                     <%  
  6.                                         foreach (TblDownload item in dislist )
  7.                                         {
  8.                     
  9.                                     %>
  10.                                                     <tr>
  11.                                                         <td class="bg-bottom" width="5%" background="/images/z7_21.gif"><IMG height="11" src="/images/z5_22.gif" width="12"></td>
  12.                                                         <td class="bg-bottom" width="95%" background="/images/z7_21.gif" height="22"><a 
  13.                         href="<%=URL+DownFile+item.FilePath%>" target=_blank 
  14.                         ><%=item.Remark%></a>
  15.                                                             <%TimeSpan dts = DateTime.Now-item.PublicDate;%>
  16.                                                             <%if(dts.Days<=30)%>
  17.                                                             <IMG src="/images/new.gif"></td>
  18.                                                     </tr>
  19.                                                     <%}%>
  20.                                                 </table>
  21.                                             </td>
  22.                                         </tr>
  23.                                     </table>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值