上一篇写了一个简单的自定义分页控件,当时写的不够完善,不能自定义控件的样式.现在完善了,望同大家共同探讨.
现在已经在网上发布的分页控件特别多,而且大多都功能特别强,但是之所以选择自己写,主要是因为自己写可以根据自己的要求来设计,不用的功能就功能免了.
本控件可以自定义样式,而且传入的参数和其它常用的分页控件差不多,记录总数和一页的数量,是否自定义样式,当页面数量特别多的时候,可以在分页信息栏中显示前几页和后几页.
具体代码如下:
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace pagerControls
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:WebCustomControlPager runat=server></{0}:WebCustomControlPager>")]
public class WebCustomControlPager : WebControl
{
private string _pageUrl="";
/**//// <summary>
/// 当前页面地址
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[DefaultValue("")]
[Localizable(true)]
[DescriptionAttribute("当前页面地址")]
public virtual string pageUrl
{
get
{
return this._pageUrl;
}
set
{
this ._pageUrl = value;
}
}
private int _currentPageIndex;
/**//// <summary>
/// 当前页面索引
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[Localizable(true)]
[DescriptionAttribute("当前页面索引从1开始")]
[DefaultValueAttribute("当前页面索引")]
public virtual int currentPageIndex
{
get
{
return this._currentPageIndex;
}
set
{
this._currentPageIndex = value;
}
}
private int _IsCustomStyle;
/**//// <summary>
/// 是否自定义样式
/// 0:不是 1:是
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[Localizable(true)]
[DescriptionAttribute("是否自定义样式")]
[DefaultValueAttribute("0")]
public virtual int IsCustomStyle
{
get
{
return this._IsCustomStyle;
}
set
{
this._IsCustomStyle = value;
}
}
private int _iRecordCount=1;
/**//// <summary>
/// 记录数量
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[Localizable(true)]
[DescriptionAttribute("记录数量")]
[DefaultValueAttribute("记录数量")]
public virtual int iRecordCount
{
get
{
return this._iRecordCount;
}
set
{
this._iRecordCount = value;
}
}
private int _iRowsCount=10;
/**//// <summary>
/// 每页记录数量
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[Localizable(true)]
[DescriptionAttribute("每页记录数量")]
[DefaultValueAttribute("每页记录数量")]
public virtual int iRowsCount
{
get
{
return this._iRowsCount;
}
set
{
this._iRowsCount = value;
}
}
private int _iPrevCount=5;
/**//// <summary>
/// 前部分记录数量
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[Localizable(true)]
[DescriptionAttribute("前部分记录数量")]
[DefaultValueAttribute("前部分记录数量")]
public virtual int iPrevCount
{
get
{
return this._iPrevCount;
}
set
{
this._iPrevCount = value;
}
}
private int _iNextCount=5;
/**//// <summary>
/// 后部分记录数量
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[Localizable(true)]
[DescriptionAttribute("后部分记录数量")]
[DefaultValueAttribute("后部分记录数量")]
public virtual int iNextCount
{
get
{
return this._iNextCount ;
}
set
{
this._iNextCount = value;
}
}
/**//// <summary>
/// 取得默认样式表信息
/// by minjiang 08-3-24
/// </summary>
/// <returns></returns>
private string styleHtml()
{
//分页样式表信息
string sStyle = "";
StringBuilder strbStyle = new StringBuilder();
sStyle = "<style type =\"text/css\" >";
strbStyle.Append(sStyle);
样式内容#region 样式内容
sStyle = ".a4:link,.a4:visited,.a4:active{color:#207FC3;font-size:12px;text-decoration:none;}";
strbStyle.Append(sStyle);
sStyle = ".a4:hover{color:#ff6600;font-size:12px;text-decoration:none;}";
strbStyle.Append(sStyle);
sStyle = ".a5:link,.a5:visited,.a5:active{color:#ffffff;font-size:12px;text-decoration:none;}";
strbStyle.Append(sStyle);
sStyle = ".a5:hover{color:#ffffff;font-size:12px;text-decoration:none;}";
strbStyle.Append(sStyle);
sStyle = ".survey_pagediv {float:left;width:950px;height:22px; margin-top:15px;}";
strbStyle.Append(sStyle);
sStyle = ".survey_pagediv .pagedivcenter { width:600px; margin: 0 auto;}";
strbStyle.Append(sStyle);
sStyle = ".survey_pagediv .page { float:left;width:auto;font-family: Verdana, Arial, Helvetica, sans-serif;}";
strbStyle.Append(sStyle);
sStyle = ".survey_pagediv .page .select{float:left;height:16px;line-height:16px;padding:0 4px 0 4px;display:block;border:solid 1px #207FC3;margin:0 2px 0 2px;background-color:#207FC3;}";
strbStyle.Append(sStyle);
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace pagerControls
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:WebCustomControlPager runat=server></{0}:WebCustomControlPager>")]
public class WebCustomControlPager : WebControl
{
private string _pageUrl="";
/**//// <summary>
/// 当前页面地址
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[DefaultValue("")]
[Localizable(true)]
[DescriptionAttribute("当前页面地址")]
public virtual string pageUrl
{
get
{
return this._pageUrl;
}
set
{
this ._pageUrl = value;
}
}
private int _currentPageIndex;
/**//// <summary>
/// 当前页面索引
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[Localizable(true)]
[DescriptionAttribute("当前页面索引从1开始")]
[DefaultValueAttribute("当前页面索引")]
public virtual int currentPageIndex
{
get
{
return this._currentPageIndex;
}
set
{
this._currentPageIndex = value;
}
}
private int _IsCustomStyle;
/**//// <summary>
/// 是否自定义样式
/// 0:不是 1:是
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[Localizable(true)]
[DescriptionAttribute("是否自定义样式")]
[DefaultValueAttribute("0")]
public virtual int IsCustomStyle
{
get
{
return this._IsCustomStyle;
}
set
{
this._IsCustomStyle = value;
}
}
private int _iRecordCount=1;
/**//// <summary>
/// 记录数量
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[Localizable(true)]
[DescriptionAttribute("记录数量")]
[DefaultValueAttribute("记录数量")]
public virtual int iRecordCount
{
get
{
return this._iRecordCount;
}
set
{
this._iRecordCount = value;
}
}
private int _iRowsCount=10;
/**//// <summary>
/// 每页记录数量
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[Localizable(true)]
[DescriptionAttribute("每页记录数量")]
[DefaultValueAttribute("每页记录数量")]
public virtual int iRowsCount
{
get
{
return this._iRowsCount;
}
set
{
this._iRowsCount = value;
}
}
private int _iPrevCount=5;
/**//// <summary>
/// 前部分记录数量
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[Localizable(true)]
[DescriptionAttribute("前部分记录数量")]
[DefaultValueAttribute("前部分记录数量")]
public virtual int iPrevCount
{
get
{
return this._iPrevCount;
}
set
{
this._iPrevCount = value;
}
}
private int _iNextCount=5;
/**//// <summary>
/// 后部分记录数量
/// </summary>
[Bindable(true)]
[CategoryAttribute("Appearance")]
[Localizable(true)]
[DescriptionAttribute("后部分记录数量")]
[DefaultValueAttribute("后部分记录数量")]
public virtual int iNextCount
{
get
{
return this._iNextCount ;
}
set
{
this._iNextCount = value;
}
}
/**//// <summary>
/// 取得默认样式表信息
/// by minjiang 08-3-24
/// </summary>
/// <returns></returns>
private string styleHtml()
{
//分页样式表信息
string sStyle = "";
StringBuilder strbStyle = new StringBuilder();
sStyle = "<style type =\"text/css\" >";
strbStyle.Append(sStyle);
样式内容#region 样式内容
sStyle = ".a4:link,.a4:visited,.a4:active{color:#207FC3;font-size:12px;text-decoration:none;}";
strbStyle.Append(sStyle);
sStyle = ".a4:hover{color:#ff6600;font-size:12px;text-decoration:none;}";
strbStyle.Append(sStyle);
sStyle = ".a5:link,.a5:visited,.a5:active{color:#ffffff;font-size:12px;text-decoration:none;}";
strbStyle.Append(sStyle);
sStyle = ".a5:hover{color:#ffffff;font-size:12px;text-decoration:none;}";
strbStyle.Append(sStyle);
sStyle = ".survey_pagediv {float:left;width:950px;height:22px; margin-top:15px;}";
strbStyle.Append(sStyle);
sStyle = ".survey_pagediv .pagedivcenter { width:600px; margin: 0 auto;}";
strbStyle.Append(sStyle);
sStyle = ".survey_pagediv .page { float:left;width:auto;font-family: Verdana, Arial, Helvetica, sans-serif;}";
strbStyle.Append(sStyle);
sStyle = ".survey_pagediv .page .select{float:left;height:16px;line-height:16px;padding:0 4px 0 4px;display:block;border:solid 1px #207FC3;margin:0 2px 0 2px;background-color:#207FC3;}";
strbStyle.Append(sStyle);