由于再给公司做一个网站,以前听老杨和栋哥经常说,前台要手写html尽量不用控件,后台可以考虑控件提高效率。。。。
呵呵,这个建议确实很不错,其实对于像我们这样的小菜鸟经常按照这样的想法做。。。我们有几大收获啊,前台为什么要手写html不多说了,说下我感到的好处吧。这样做我可以学习练习和熟练html等标签属性,为以后打下扎实基础,而后台不需要大量访问所以用上控件能提高开发效率,从而我们也熟悉控件开发,当以后工作中我们需要快速完成某些功能时可以通过控件为我们节约时间,而在平时手写加控件同时使用让我们对每一块都不会在生疏,不会像读书时学到后面忘前面了。。。。。
分享下repeater+存储过程+自定义控件源码
public partial class List : System.Web.UI.Page
{
List<CLModel.TLinksCLModel> tLinksCLModel = new List<CLModel.TLinksCLModel>();
//展示友情链接数据提供
public int pcount = 0; //总条数
protected string pageLable = "";
protected int nowPage = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString["page"]))
{
nowPage = int.Parse(Request.QueryString["page"]);
}
LoadContentList( nowPage);
}
//生成页面条
private void LoadContentList( int nPage)
{
int intRowCount = 0;
int intPageCount = 0;
int pageSize=10;
//使用 存储过程 执行分页【参数---当前页码,页容量,总行数(输出参数),总页数(输出参数)】
List<CLModel.TLinksCLModel> list = new CLBLL.TLinksCLBLL().QueryListByPageIndexPro(nPage, pageSize, out intRowCount, out intPageCount);
//生成页码条【参数---连接地址,查询条件,总行数,总页数,当前页码,页码组容量,页容量】
pageLable = WebHelper.GetPageTxt("List.aspx?&page=", "", intRowCount, intPageCount, nPage, 5, 3);
if(list!=null)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = list;
pds.AllowPaging = false;
pds.PageSize = pageSize;
int curPage;
if (Request.QueryString["page"] != null)
{
curPage = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
curPage = 1;
}
pds.CurrentPageIndex = curPage-1;
this.rptList.DataSource = pds;
this.rptList.DataBind();
}
}
}
#region +获得功能页码条
/// <summary>
/// 获得功能页码条
/// </summary>
/// <param name="url">页码连接地址</param>
/// <param name="searcheurl">搜索url</param>
/// <param name="allrecord">全部记录条数</param>
/// <param name="allpage">全部页面数</param>
/// <param name="curpage">当前页码</param>
/// <param name="groupsize">页码组大小</param>
/// <param name="pagesize">页容量</param>
public static string GetPageTxt(string url, string searcheurl, int allrecord, int allpage, int curpage, int groupsize, int pagesize)
{
int curGroupPage = 0;
StringBuilder test = new StringBuilder();
StringBuilder test2 = new StringBuilder();
StringBuilder pagetxt = new StringBuilder();
if (curpage.Equals("") || curpage < 1) curpage = 1;
if (allrecord.Equals("") || allrecord < 1) allrecord = 1;
if (pagesize.Equals("") || pagesize < 1) pagesize = 1;
if (allrecord == 0) { pagetxt.Append("页码:0/0 │ 共0条</TD> <td align='left'> 首页 << 上一页 | 1 Next | >> 尾页 </td></tr></table>"); }
else
{
test2.Append(allpage.ToString());
if (allpage.Equals("") || allpage < 1) allpage = 1;
pagetxt.Append("页码:" + curpage.ToString() + "/" + allpage.ToString() + " │ 共" + allrecord.ToString() + "条");
pagetxt.Append("<A href='" + url + "1' title='首页'>首页</A> ");
curGroupPage = (((curpage - 1) / groupsize) * groupsize) + 1;
if (curpage <= 1) pagetxt.Append("<A href='" + url + curpage + searcheurl + "' title='首页'>首页</A> ");
else pagetxt.Append("<A href='" + url + (curpage - 1) + searcheurl + "' title='前一页'>上一页</A> ");
int tempI = 0;
tempI = curGroupPage;
do
{
if (tempI == curpage) pagetxt.Append("<span class='nowpage'>" + tempI + "</span> ");
else pagetxt.Append("<A href='" + url + tempI + searcheurl + "'>" + tempI + "</A> ");
tempI = tempI + 1;
} while (tempI < curGroupPage + groupsize && tempI <= allpage);
if (curpage < allpage) pagetxt.Append("<A href='" + url + (curpage + 1) + searcheurl + "' title='后一页'>下一页</A> ");
else pagetxt.Append("<A href='" + url + curpage + searcheurl + "' title='后一页'>下一页</A> ");
pagetxt.Append("<A href='" + url + allpage + searcheurl + "' title='最后一页'>最后一页</A>");
}
test.Append("allpage=" + allpage + ",allrecord=" + allrecord + ",pagesize=" + pagesize + ",groupsize=" + groupsize + ",curGroupPage=" + curGroupPage + ",curpage=" + curpage);
return pagetxt.ToString();
}
#endregion
简单的存储过程
alter PROCEDURE GetLinkPageOutRowPageCount
(
@PageIndex int =1,--当前页数
@PageSize int =4,--当前页大小
@RowCount int output,--总行数(传出参数)
@PageCount int output--总页数(传出参数)
)
AS
begin
DECLARE @sql NVARCHAR(max),@sqlCount NVARCHAR(225)
select @RowCount =COUNT(FId),@PageCount=CEILING((COUNT(FId)+0.0)/@PageSize) FROM TLinks
SET @sql='SELECT TOP '+LTRIM(str(@PageSize))+' * FROM TLinks where FId not in(select top '+LTRIM(str((@PageIndex-1)*@PageSize))+' FId from TLinks order by FSortId DESC , FAddTime ASC)order by FSortId DESC , FAddTime ASC'
print @sql
EXEC(@sql)
end
数据层和bll不粘贴了 那太啰嗦。。。 能在黑马同大家一起成长是我的100分100幸福 哈哈
|