学海无涯,每天都会有新的发现,希望每天都能充实自己。
以前都是利用datagrid控件绑定数据并且分页,但最近看了一段别人写的代码,又学了不少新的知识
当然,以下代码是从程序里摘出来的,仅供参考
前台的代码
以前都是利用datagrid控件绑定数据并且分页,但最近看了一段别人写的代码,又学了不少新的知识
当然,以下代码是从程序里摘出来的,仅供参考
- //去掉了大量不必要的代码
- public IList list=null;
- public IList dislist = new ArrayList();
- #region 帮顶表格
- /// <summary>
- /// 帮顶表格
- /// </summary>
- public void BindData()
- {
- GetDownloadList("","");
- if(null!=dislist)dislist.Clear();
- int start =(CurrIndex-1)*PageSize+1;
- for(int i=start;i<=CurrIndex*PageSize && i<=list.Count;i++)
- {
- TblDownload tbldown = (TblDownload)list[i-1];
- dislist.Add(tbldown);
- }
- }
- #endregion
- public void GetDownloadList(string region,string popedom)
- {
- Download downloads=new Download();
- TblDownload tblDownload=new TblDownload();
- //tblDownload.Category="COMMUNION";
- tblDownload.Region = downloads.GetAgtRegion(strAgentID);
- if(tblDownload.Region =="S1") //总部地区
- tblDownload.Region = "TJ"; //总部
- strAgentType = promoteStandard.GetPromoteType(strAgentLevel);
- tblDownload.Popedom=strAgentType;
- list=downloads.GetTop5FileList(tblDownload);
- Rectotal=list.Count;
- }
- /// <summary>
- /// 说明:下载文件
- /// </summary>
- /// <param name="tblDownload">下载对象</param>
- /// <returns>
- /// 返回文件列表
- /// </returns>
- public IList GetTop5FileList(TblDownload tblDownload)
- {
- IList list = new ArrayList();
- string SqlString = "select top 5 * from tblDownLoad where filepath <> '0' order by tblDownload.fileId desc";
- SqlConnection connection = new SqlConnection( ConfigurationGlobals.ConnectionSqlString);
- SqlCommand command = new SqlCommand(SqlString,connection);
- SqlDataReader reader = null;
- try
- {
- connection.Open();
- reader = command.ExecuteReader(CommandBehavior.CloseConnection);
- while(reader.Read())
- {
- TblDownload tbldownload = TblDownload.GetModel( reader );
- list.Add(tbldownload);
- }
- }
- catch(Exception e)
- {
- throw new DataAccessException(e.Message);
- }
- finally
- {
- if(reader != null)
- reader.Close();
- }
- return list;
- }
- #endregion
- <table height="44" cellSpacing="0" cellPadding="0" width="760" border="0">
- <tr>
- <td width="239">
- <table height="22" cellSpacing="0" cellPadding="0" width="752" border="0">
- <%
- foreach (TblDownload item in dislist )
- {
- %>
- <tr>
- <td class="bg-bottom" width="5%" background="/images/z7_21.gif"><IMG height="11" src="/images/z5_22.gif" width="12"></td>
- <td class="bg-bottom" width="95%" background="/images/z7_21.gif" height="22"><a
- href="<%=URL+DownFile+item.FilePath%>" target=_blank
- ><%=item.Remark%></a>
- <%TimeSpan dts = DateTime.Now-item.PublicDate;%>
- <%if(dts.Days<=30)%>
- <IMG src="/images/new.gif"></td>
- </tr>
- <%}%>
- </table>
- </td>
- </tr>
- </table>