asp.net Repeater之非常好的数据分页

时间:2021-05-28

分页控件源代码如下:
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

#region Assembly Resource Attribute
[assembly: System.Web.UI.WebResource("WebControlLibrary.Js.AjaxHelper.js", "text/javascript")]
[assembly: System.Web.UI.WebResource("WebControlLibrary.img.bg_pager.png", "image/gif")]
#endregion

namespace WebControlLibrary
{
/// <summary>
/// Repeater分页控件可进行Ajax分页(但Ajax分页不能传参数)
/// </summary>
[DefaultProperty("Text")]
[ToolboxData("<{0}:RepeaterPages runat=server></{0}:RepeaterPages>")]
public class RepeaterPages : WebControlLibrary.Repeater
{
// <summary>
/// 构造函数
/// </summary>
public RepeaterPages()
: base()
{

}

/// <summary>
/// 下一页分页文本内容
/// </summary>
private string _NextPage = ">";

/// <summary>
/// 下一页标记
/// </summary>
[Bindable(false), Description("下一页标记所显示的文本内容")]
public string NextPage
{
get { return _NextPage; }

set { _NextPage = value; }
}

/// <summary>
/// 下一页标记
/// </summary>
private string _LastPage = "<";

/// <summary>
/// 上一页标记
/// </summary>
[Bindable(false), Description("上一页标记所显示的文本内容")]
public string LastPage
{
get { return _LastPage; }

set { _LastPage = value; }
}

/// <summary>
/// 总记录数属性
/// </summary>
private int _RecordCount;

/// <summary>
/// 页面分页大小属性
/// </summary>
private int _PageSize;

/// <summary>
/// 当前页数
/// </summary>
private int _CurrentPage;

/// <summary>
/// 返回总页面
/// </summary>
private int _AllPages;

/// <summary>
/// 页面地址
/// </summary>
private string _Url;

/// <summary>
/// 传入Sql语句
/// </summary>
private string _SqlString;

/// <summary>
/// 每页显示页码数
/// </summary>
private int _PageNumberCount;

/// <summary>
/// 数据库中显示的字段列表
/// </summary>
private string _ShowTableCollName;

/// <summary>
/// 记录数属性
/// </summary>
[Bindable(true), Category("Appearance"), DefaultValue("0")]
private int RecordCount
{
get
{
int IntTempValue = 0;
if (Int32.TryParse(Sql_Function.SqlDb.RecordCounts(SqlString), out IntTempValue))
return IntTempValue;
else
return 0;
}
set
{
_RecordCount = value;
}
}

/// <summary>
/// 每页分页大小属性
/// </summary>
[Bindable(true), Category("Appearance"), DefaultValue("50"), Description("每页分页大小属性")]
public int PageSize
{
get
{
if (_PageSize == 0 || _PageSize.ToString() == "" || _PageSize > 200)
{
return 50;
}
else if (Sql_Function.PublicFunction.isNumber(_PageSize.ToString()))
{
return 50;
}
else if (_PageSize <= 0)
{
return 50;
}
else if (_PageSize > 200)
{
return 50;
}
else
{
return _PageSize;
}
}

set { _PageSize = value; }
}

/// <summary>
/// 每页显示的页码个数
/// </summary>
[Bindable(true), Category("Appearance"), DefaultValue("5"), Description("每页显示的页码个数")]
public int PageNumberCount
{
get
{
if (_PageNumberCount == 0 || _PageNumberCount.ToString() == "" || _PageNumberCount > 30)
{
return 5;
}
else if (Sql_Function.PublicFunction.isNumber(_PageNumberCount.ToString()))
{
return 5;
}
else if (_PageNumberCount <= 0)
{
return 5;
}
else if (_PageNumberCount > 30)
{
return 5;
}
else
{
return _PageNumberCount;
}
}

set { _PageNumberCount = value; }
}

/// <summary>
/// 返回总页数
/// </summary>
private int AllPages
{
get
{
int totalpage;

if (RecordCount / PageSize == 0)
{
totalpage = RecordCount / PageSize;
}
else
{
totalpage = RecordCount / PageSize + 1;
}

return totalpage;
}

set { _AllPages = value; }
}

/// <summary>
/// 当前页数
/// </summary>
private int CurrentPage
{
get
{
string RequestCurrentPage = System.Web.HttpContext.Current.Request["page"];

#region 计算当前页数

int result_currentpage = 1;

if (RequestCurrentPage == null)///指地址栏中没有PAGE字符
{
result_currentpage = 1;
}

if (RequestCurrentPage != null)
{

if (RequestCurrentPage.Length > 10 || RequestCurrentPage.Length < 1)///防止Convert.ToInt32抛出异常或者防止地址栏所得到的page=这样的值
{
result_currentpage = 1;
}
else///是数值
{
if (Sql_Function.PublicFunction.isNumber(RequestCurrentPage))// 判断是否为数值
{
result_currentpage = 1;
}
else
{
if (Convert.ToInt32(RequestCurrentPage) > AllPages)///是否大于总页数
{
result_currentpage = 1;
}
else
{
if (Convert.ToInt32(RequestCurrentPage) <= 1)///是否小于页数1
{
result_currentpage = 1;
}
else
{
result_currentpage = Convert.ToInt32(RequestCurrentPage);
}
}
}
}
}
else
{
result_currentpage = 1;
}

return result_currentpage;

#endregion

}

set { _CurrentPage = value; }
}

/// <summary>
/// 用于分页所显示URL参数链接(完整的URL参数)
/// </summary>
[Bindable(false), Description("用于分页所显示URL参数链接(完整的URL参数)")]
public string Url
{
get
{
if (_Url == null || _Url.ToString() == "")
{
return "?";
}
else
{
if (_Url.IndexOf("?") == -1)
{
string a = "?";

a = a + _Url;

return a;
}
else if (Convert.ToInt32(StringFindCount(_Url, "?")) > 1)//如果含有多个?号
{
return "?";
}
else
{
return _Url;
}

}
}

set { _Url = value; }
}

/// <summary>
/// 传入Sql语句
/// </summary>
[Bindable(false), Description("传入统计记录总数的Sql语句 例如:select count(id) from tablename")]
public string SqlString
{
get
{
if (_SqlString == null || _SqlString.ToString() == "" || _SqlString.Length < 15)
{
return "";
}
else
{
return _SqlString;
}
}

set { _SqlString = value; }
}

/// <summary>
/// 数据库中显示的字段列表
/// </summary>
[Bindable(false), Description("数据库中显示的字段列表 多个字段中间用逗号隔开")]
public string ShowTableCollName
{
get
{
if (_ShowTableCollName == null || _ShowTableCollName == "")
{
return "*";
}
else
{
return _ShowTableCollName;
}
}

set { _ShowTableCollName = value; }
}

/// <summary>
/// 分页信息前和尾所包含的HTML代码
/// </summary>
private string _PageBeforeHtml;

/// <summary>
/// 分页信息前和尾所包含的HTML代码
/// </summary>
private string _PageLastHtml;

/// <summary>
/// 分页信息前和尾所包含的HTML代码
/// </summary>
[Bindable(false), Description("分页信息前和尾所包含的HTML代码 ")]
public string PageBeforeHtml
{
get { return _PageBeforeHtml; }

set { _PageBeforeHtml = value; }
}

/// <summary>
/// 分页信息前和尾所包含的HTML代码
/// </summary>
[Bindable(false), Description("分页信息前和尾所包含的HTML代码 ")]
public string PageLastHtml
{
get { return _PageLastHtml; }

set { _PageLastHtml = value; }
}

/// <summary>
/// 调用的样式
/// </summary>
private string _Css = "";

/// <summary>
/// 调用的样式
/// </summary>
[Bindable(false), Category("Behavior"), DefaultValue("默认样式"), TypeConverter(typeof(WebPageCssSelect)), Description("分页样式")]
public string Css
{
get { return _Css; }

set { _Css = value; }
}

/// <summary>
/// 是否为分页加上快捷输入框输入数值回车导航分页
/// </summary>
private bool _SelectPage = true;

/// <summary>
/// 是否为分页加上快捷输入框输入数值回车导航分页
/// </summary>
[Bindable(false), Description("是否为分页加上快捷输入框输入数值回车导航分页")]
public bool SelectPage
{
get { return _SelectPage; }

set { _SelectPage = value; }
}

/// <summary>
/// 分页显示对齐方式
/// </summary>
private string _AlignSorts = "right";

/// <summary>
/// 分页显示对齐方式
/// </summary>
[Bindable(false), DefaultValue("right"), TypeConverter(typeof(WebPageAlign)), Description("分页显示对齐方式")]
public string AlignSorts
{
get { return _AlignSorts; }

set { _AlignSorts = value; }
}

/// <summary>
/// 分页Js分页函数调用名称
/// </summary>
private string _JsFunctionName = "_doPostBack";

/// <summary>
/// 分页Js分页函数调用名称
/// </summary>
[Bindable(false), Description("分页Js分页函数调用名称")]
public string JsFunctionName
{
get
{
if (_JsFunctionName == null || _JsFunctionName.Replace("'", "").Replace("\"", "") == "")
{
return "_doPostBack";
}
else
{
return _JsFunctionName;
}
}

set { _JsFunctionName = value; }
}

/// <summary>
/// 是否启用简洁分页样式
/// </summary>
private bool _AutoPageConcise = false;

/// <summary>
/// 是否启用简洁分页样式
/// </summary>
[Bindable(false), Description("是否启用简洁分页样式")]
public bool AutoPageConcise
{
set { _AutoPageConcise = value; }

get { return _AutoPageConcise; }
}

/// <summary>
/// 是否允许无刷新调用分页
/// </summary>
private bool _BoolIsAutoAjaxPage = false;

/// <summary>
/// 是否允许无刷新调用分页
/// </summary>
[Bindable(false), Description("是否允许无刷新调用分页")]
public bool BoolIsAutoAjaxPage
{
get { return _BoolIsAutoAjaxPage; }

set { _BoolIsAutoAjaxPage = value; }
}

/// <summary>
/// 无刷新调用的页面或自定义控件页面ascx分页信息页 完整路径
/// </summary>
private string _AutoAjaxPageUrl = "";

/// <summary>
/// 无刷新调用的页面或自定义控件页面ascx分页信息页 完整路径
/// </summary>
[Bindable(false), Description("无刷新调用的页面或自定义控件页面ascx分页信息页 完整路径")]
public string AutoAjaxPageUrl
{
get { return _AutoAjaxPageUrl; }

set { _AutoAjaxPageUrl = value; }
}

/// <summary>
/// 用于无刷新中间级异步调用分页信息页面的中间层页面地址
/// </summary>
private string _AutoAjaxReturnPageUrl = "";

/// <summary>
/// 用于无刷新中间级异步调用分页信息页面的中间层页面地址
/// </summary>
[Bindable(false), Description("用于无刷新中间级异步调用分页信息页面的中间层页面地址")]
public string AutoAjaxReturnPageUrl
{
get { return _AutoAjaxReturnPageUrl; }

set { _AutoAjaxReturnPageUrl = value; }
}

/// <summary>
/// 无刷新调用的页面所返回的控件ID
/// </summary>
private string _AutoAjaxPageWebControl = "";

/// <summary>
/// 无刷新调用的页面所返回的控件ID
/// </summary>
[Bindable(false), Description("无刷新调用的页面所返回的控件ID")]
public string AutoAjaxPageWebControl
{
get { return _AutoAjaxPageWebControl; }

set { _AutoAjaxPageWebControl = value; }
}

/// <summary>
/// 输出html,在浏览器中显示控件
/// </summary>
/// <param name="output"> 要写出到的 HTML 编写器 </param>
protected override void Render(HtmlTextWriter output)
{
base.Render(output);

if (!this.Page.ClientScript.IsClientScriptBlockRegistered(this.Page.GetType(), "AjaxPageJs"))
{
output.Write("\n<script type=\"text/javascript\">var AjaxUrl='" + AutoAjaxReturnPageUrl + "';</script>");

output.Write("\n<script type=\"text/javascript\" src=\"" + this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "WebControlLibrary.Js.AjaxHelper.js") + "\"></script>");

this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "AjaxPageJs", "");
}

#region 输出分页链接样式

string CssInfo = WebPageCss.CssStyle(Css, AlignSorts, this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "WebControlLibrary.img.bg_pager.png"));

output.WriteLine(CssInfo);

#endregion

#region 输出分页Js

output.WriteLine("<script language=\"JavaScript\">\n");

output.WriteLine(" function " + JsFunctionName + "(Obj,PageIndex)\n");

output.WriteLine(" {\n");

if (BoolIsAutoAjaxPage)
{
output.WriteLine(" AjaxHelper.Updater('" + AutoAjaxPageUrl.Replace("'", "").Replace("\"", "") + "','" + AutoAjaxPageWebControl + "','" + System.Web.HttpContext.Current.Request.ServerVariables["QUERY_STRING"] + "&page=' + PageIndex + '');\n");

}
else
{
output.WriteLine(" var getUrl=\"" + Url.Replace("'", "").Replace("\"", "") + "&page=\" + PageIndex + \"\";\n");

output.WriteLine(" document.location.href=getUrl;\n");
}

output.WriteLine(" }\n");

output.WriteLine("</script>\n");

#endregion

if (!DesignMode)
{
string Result = Pagination();

if (RecordCount > PageSize)
{
output.WriteLine(Result);
}
}
}

/// <summary>
/// 调用存储过程返回数据集
/// </summary>
/// <param name="IsProc">是否启用存储过程调用数据 true:启用</param>
/// <param name="PorcedureName">存储过程名</param>
/// <param name="TableName">表名</param>
/// <param name="TableCollName">表中该列来进行分页(必须是唯一性的字符,比如标识种子</param>
/// <param name="OrderBy">完整的排序字段值 不需要order by </param>
/// <param name="Where">存储过程分页中的条件 不需要Where</param>
/// <returns></returns>
public System.Data.DataTable getObjectRecordCount(bool IsProc, string PorcedureName, string TableName, string TableCollName, string OrderBy, string Where)
{
System.Data.DataTable DataTables = new System.Data.DataTable();

if (IsProc)
{
DataTables = Sql_Function.SqlDb.ReturnDataTable("" + PorcedureName + " '" + TableName + "','" + TableCollName + "'," + CurrentPage + "," + PageSize + ",'" + ShowTableCollName.Replace("'", "") + "','" + OrderBy + "','" + Where + "'");
}
else//普通分页
{
string StrSql = string.Format("select {0} from {1} where {2} is not null", ShowTableCollName, TableName, TableCollName);

if (Where != null && Where.Trim().Replace("'", "") != "")
{
StrSql += " and " + Where.Trim().Replace("'", "");
}

if (OrderBy != null && OrderBy.Trim().Replace("'", "") != "")
{
StrSql += " order by " + OrderBy.Trim().Replace("'", "");
}

try
{
DataTables = Sql_Function.SqlDb.ReturnDataTablePage(StrSql, CurrentPage, PageSize, "ReturnDataTable");
}
catch
{
DataTables = null;
}
}

return DataTables;
}

/// <summary>
/// 分页函数
/// </summary>
/// <param name="TotalRecordCount">总记录数</param>
/// <param name="Url">Url地址</param>
/// <param name="CurrentPage">当前页数</param>
public string Pagination()
{
int allpage = 0;//总页数

int next = 0;//下页标记

int pre = 0;//上一页标记

int startcount = 0;//开始页码数

int endcount = 0;//结束页码数

string pagestr = "";//返回分页结果集

if (CurrentPage < 1) { CurrentPage = 1; }

//计算总页数
if (PageSize != 0)
{
allpage = (RecordCount / PageSize);

allpage = ((RecordCount % PageSize) != 0 ? allpage + 1 : allpage);

allpage = (allpage == 0 ? 1 : allpage);
}

next = CurrentPage + 1;

pre = CurrentPage - 1;

if (PageNumberCount % 2 == 0)
{
startcount = (CurrentPage + PageNumberCount / 2) > allpage ? allpage - (PageNumberCount - 1) : CurrentPage - (PageNumberCount / 2 - 1);

endcount = CurrentPage < PageNumberCount / 2 ? PageNumberCount : CurrentPage + PageNumberCount / 2;

}
else
{
startcount = (CurrentPage + PageNumberCount / 2) > allpage ? allpage - (PageNumberCount - 1) : CurrentPage - (PageNumberCount / 2 - 1);

endcount = CurrentPage < PageNumberCount / 2 ? PageNumberCount : CurrentPage + PageNumberCount / 2 + 1;

}

if (startcount < 1) { startcount = 1; } //为了避免输出的时候产生负数,设置如果小于1就从序号1开始

if (allpage < endcount) { endcount = allpage; }//页码+5的可能性就会产生最终输出序号大于总页码,那么就要将其控制在页码数之内

pagestr = "\n" + PageBeforeHtml + "\n";

pagestr += "<div class=\"pages-nav\">\n";

if (!AutoPageConcise)
{
pagestr += " <span class=\"default\">页次:<strong>" + CurrentPage + "</strong>/<strong>" + allpage + "</strong> \n";

pagestr += "每页<strong>" + PageSize.ToString() + "</strong>\n";

pagestr += " 记录数<strong>" + RecordCount + "</strong>&nbsp;&nbsp;&nbsp;\n </span>";
}

#region 上一页标记

//pagestr += CurrentPage > 1 ? "<a href=\"" + Url + "&page=1\">1..</a>&nbsp;<a href=\"" + Url + "&page=" + pre + "\">" + LastPage + "</a>" : "<span class=\"disabled\">" + LastPage + "</span>";
pagestr += CurrentPage > 1 ? "<a href=\"javascript:" + JsFunctionName + "('" + this.ClientID.ToString() + "','1')\">1..</a>&nbsp;<a href=\"javascript:" + JsFunctionName + "('" + this.ClientID.ToString() + "','" + pre + "')\">" + LastPage + "</a>" : "<span class=\"disabled\">" + LastPage + "</span>";

#endregion

#region 中间页处理,这个增加时间复杂度,减小空间复杂度

////中间页处理,这个增加时间复杂度,减小空间复杂度
for (int i = startcount; i <= endcount; i++)
{
//pagestr += CurrentPage == i ? "&nbsp;<span class=\"current\">" + i + "</span>" : "&nbsp;<a href=\"" + Url + "&page=" + i + "\" >" + i + "</a>";
pagestr += CurrentPage == i ? "&nbsp;\n<span class=\"current\">" + i + "</span>" : "&nbsp;\n<a href=\"javascript:" + JsFunctionName + "('" + this.ClientID.ToString() + "','" + i + "')\">" + i + "</a>";
}

#endregion

#region 下一页标记

//pagestr += CurrentPage != allpage ? "&nbsp;<a href=\"" + Url + "&page=" + next + "\">" + NextPage + "</a>&nbsp;<a href=\"" + Url + "&page=" + allpage + "\">.." + allpage + "</a>" : "<span class=\"disabled\">" + NextPage + "</span>";

pagestr += CurrentPage != allpage ? "&nbsp;<a href=\"javascript:" + JsFunctionName + "('" + this.ClientID.ToString() + "','" + next + "')\">" + NextPage + "</a>&nbsp;<a href=\"javascript:" + JsFunctionName + "('" + this.ClientID.ToString() + "','" + allpage + "')\">.." + allpage + "</a>" : "<span class=\"disabled\">" + NextPage + "</span>";

#endregion

if (SelectPage)
{
pagestr += "&nbsp;\n<input type=\"text\" title=\"输入数字,回车跳转\" size=\"3\" onkeydown=\"return PagegetUrls(this.value);\" value=\"" + CurrentPage + "\" class=\"PageCssInput\" style=\"cursor:hand\" />";

pagestr += "\n<script>\nfunction PagegetUrls(Values)\n{\n if (13==event.keyCode)\n {\n javascript:" + JsFunctionName + "('" + this.ClientID.ToString() + "',Values)\n return false;\n }\n}\n</script>\n";
}

pagestr += "\n</div>\n" + PageLastHtml + "\n";

return pagestr;
}

/// <summary>
/// 跳转
/// </summary>
/// <param name="pagecount">总页数</param>
/// <param name="currentpage">当前页数</param>
/// <param name="Url">传入链接地址</param>
/// <returns></returns>
private string SelectPages(int PageCount, int CurrentPage, string Url)
{
string ResultPage = "";

for (int k = 1; k <= PageCount; k++)
{
if (k == CurrentPage)
{
ResultPage += "<option value=\"" + Url + "&page=" + k + "\" selected>" + k + "</option>";
}
else
{
ResultPage += "<option value=\"" + Url + "&page=" + k + "\">" + k + "</option>";
}
}

return ResultPage;
}

/// <summary>
/// 判断某一字符出现的次数
/// </summary>
/// <param name="str">目标字符串</param>
/// <param name="split">要查找的字符 只能为字符,不能为字符串,如果为字符串,则自动洁取第一个字符为默认的字符</param>
/// <returns></returns>
private string StringFindCount(string str, string split)
{
int c1 = 0;

string a = split;

if (split == null || split.ToString() == "" || split.ToString().Trim().Length < 1)
{
a = " ";
}
else if (split.ToString().Trim().Length > 1)
{
a = a.Substring(0, 1);
}
else
{

}
if (str == null || str.ToString().Trim().Replace("'", "") == "" || str.ToString().Trim().Replace("'", "").Length < 1)
{
c1 = 0;
}
else
{
for (int i = 0; i < str.Length; i++)
{
if (str[i] == char.Parse(a))
{
c1++;
}
}
}
return c1.ToString();
}
}

/// <summary>
/// 分页样式选择器
/// </summary>
public class WebPageCssSelect : StringConverter
{
/// <summary>
/// 构造函数
/// </summary>
public WebPageCssSelect() { }

/// <summary>
/// 分页样式选择器编辑属性
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}

/// <summary>
/// 获取标准值列表
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
ArrayList CssArray = new ArrayList();
CssArray.Add("Digg Style");
CssArray.Add("Yahoo Style");
CssArray.Add("New Yahoo! Style");
CssArray.Add("Meneame Style");
CssArray.Add("Flickr Style");
CssArray.Add("Sabros.us Style");
CssArray.Add("Green Style");
CssArray.Add("Gray Style");
CssArray.Add("Black Style");
CssArray.Add("Mis Algoritmos Style");
CssArray.Add("Black-Red Style");
CssArray.Add("Gray Style 2");
CssArray.Add("Yellow Style");
CssArray.Add("jogger Style");
CssArray.Add("512megas Style");
CssArray.Add("Technorati Style");
CssArray.Add("YouTube Style");
CssArray.Add("MSDN Search Style");
CssArray.Add("Msn Gray Style");
CssArray.Add("Badoo");
CssArray.Add("Blue Style");
CssArray.Add("Green-Black Style");
CssArray.Add("viciao Style");
CssArray.Add("默认样式");
return new StandardValuesCollection(CssArray);

}

/// <summary>
/// return ture的话只能选,return flase可选可填
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
}

/// <summary>
/// 样式对齐方式
/// </summary>
public class WebPageAlign : StringConverter
{
/// <summary>
/// 构造函数
/// </summary>
public WebPageAlign() { }

/// <summary>
/// 分页样式选择器编辑属性
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}

/// <summary>
/// 获取标准值列表
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
ArrayList CssArray = new ArrayList();
CssArray.Add("right");
CssArray.Add("left");
CssArray.Add("center");
return new StandardValuesCollection(CssArray);

}

/// <summary>
/// return ture的话只能选,return flase可选可填
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
}

/// <summary>
/// 返回样式内容
/// </summary>
public class WebPageCss
{
/// <summary>
/// 返回样式中内容
/// </summary>
/// <param name="Css">样式种类</param>
/// <param name="AlignSorts">样式对齐方式</param>
/// <param name="BackGroundImageUrl">背景图片</param>
/// <returns></returns>
public static string CssStyle(string Css, string AlignSorts,string BackGroundImageUrl)
{
string Result = "";

#region 输出分页链接样式

Result+="\n<style type=\"text/css\">\n";

#region 分页样式控制

if (Css == "默认样式" || Css == "")//默认分页样式
{
Result+="\n.pages-nav { PADDING-RIGHT: 2px; PADDING-LEFT: 2px; PADDING-BOTTOM: 1px; PADDING-TOP: 1px; TEXT-ALIGN: " + AlignSorts + ";clear:both;}";

Result+="\n.pages-nav a { PADDING-RIGHT: 2px; PADDING-LEFT: 2px; PADDING-BOTTOM: 1px;PADDING-TOP: 1px;}";

Result+="\n.pages-nav a:hover { PADDING-RIGHT: 2px; PADDING-LEFT: 2px;PADDING-BOTTOM: 1px; PADDING-TOP: 1px;background: #F30; border-color: #ddd; color: #fff; text-decoration: none;}";

Result+="\n.pages-nav a:active {PADDING-RIGHT: 2px; PADDING-LEFT: 2px; PADDING-BOTTOM: 1px;PADDING-TOP: 1px;}";

Result+="\n.pages-nav SPAN.current {PADDING-RIGHT: 2px; PADDING-LEFT: 2px; PADDING-BOTTOM: 1px; COLOR: #ff00ff; PADDING-TOP: 1px;}";

Result+="\n.pages-nav SPAN.default {PADDING-RIGHT: 2px; PADDING-LEFT: 2px; ; PADDING-BOTTOM: 1px; PADDING-TOP: 1px;}";

Result+="\n.pages-nav SPAN.disabled {PADDING-RIGHT:2px; PADDING-LEFT:2px; PADDING-BOTTOM:1px; COLOR: #ddd; PADDING-TOP: 1px;}";

Result+="\n.pages-nav input.PageCssInput {PADDING-RIGHT: 2px; PADDING-LEFT: 2px; ; PADDING-BOTTOM: 1px; PADDING-TOP: 1px;border:1px #cccccc solid}";
}
else if (Css == "Digg Style")
{
Result+="\n.pages-nav { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: " + AlignSorts + ";clear:both;}";

Result+="\n.pages-nav a { BORDER-RIGHT: #aaaadd 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #aaaadd 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #aaaadd 1px solid; COLOR: #000099; PADDING-TOP: 2px; BORDER-BOTTOM: #aaaadd 1px solid; TEXT-DECORATION: none}";

Result+="\n.pages-nav a:hover { BORDER-RIGHT: #000099 1px solid; BORDER-TOP: #000099 1px solid; BORDER-LEFT: #000099 1px solid; COLOR: #000; BORDER-BOTTOM: #000099 1px solid}";

Result+="\n.pages-nav a:active { BORDER-RIGHT: #000099 1px solid; BORDER-TOP: #000099 1px solid; BORDER-LEFT: #000099 1px solid; COLOR: #000; BORDER-BOTTOM: #000099 1px solid }";

Result+="\n.pages-nav SPAN.current {BORDER-RIGHT: #000099 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #000099 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #000099 1px solid; COLOR: #fff; PADDING-TOP: 2px; BORDER-BOTTOM: #000099 1px solid; BACKGROUND-COLOR: #000099}";

Result+="\n.pages-nav SPAN.default {PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; COLOR: #000099; PADDING-TOP: 2px; TEXT-DECORATION: none}";

Result+="\n.pages-nav SPAN.disabled {BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #ddd; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid}";

Result+="\n.pages-nav input.PageCssInput {BORDER-RIGHT: #aaaadd 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #aaaadd 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #aaaadd 1px solid; COLOR: #000099; PADDING-TOP: 2px; BORDER-BOTTOM: #aaaadd 1px solid; TEXT-DECORATION: none}";
}
else if (Css == "Yahoo Style")
{
Result+="\n.pages-nav { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px;TEXT-ALIGN: " + AlignSorts + ";clear:both;}";

Result+="\n.pages-nav a { BORDER-RIGHT: #fff 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #fff 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #fff 1px solid; COLOR: #000099; PADDING-TOP: 2px; BORDER-BOTTOM: #fff 1px solid; TEXT-DECORATION: underline}";

Result+="\n.pages-nav a:hover { BORDER-RIGHT: #000099 1px solid; BORDER-TOP: #000099 1px solid; BORDER-LEFT: #000099 1px solid; COLOR: #000; BORDER-BOTTOM: #000099 1px solid}";

Result+="\n.pages-nav a:active {BORDER-RIGHT: #000099 1px solid; BORDER-TOP: #000099 1px solid; BORDER-LEFT: #000099 1px solid; COLOR: #f00; BORDER-BOTTOM: #000099 1px solid }";

Result+="\n.pages-nav SPAN.current {BORDER-RIGHT: #fff 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #fff 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #fff 1px solid; COLOR: #000; PADDING-TOP: 2px; BORDER-BOTTOM: #fff 1px solid; BACKGROUND-COLOR: #fff}";

Result+="\n.pages-nav SPAN.default {PADDING-RIGHT: 5px;PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; COLOR: #000099; PADDING-TOP: 2px; TEXT-DECORATION: none}";

Result+="\n.pages-nav SPAN.disabled {BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #ddd; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid}";

Result+="\n.pages-nav input.PageCssInput {BORDER-RIGHT: #fff 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #fff 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #fff 1px solid; COLOR: #000099; PADDING-TOP: 2px; BORDER-BOTTOM: #fff 1px solid; TEXT-DECORATION: underline}";
}
else if (Css == "New Yahoo! Style")
{
Result+="\n.pages-nav { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; FONT-FAMILY: Tahoma,Helvetica,sans-serif; TEXT-ALIGN: " + AlignSorts + ";clear:both;}";

Result+="\n.pages-nav a { BORDER-RIGHT: #ccdbe4 1px solid; PADDING-RIGHT: 8px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #ccdbe4 1px solid; PADDING-LEFT: 8px; PADDING-BOTTOM: 2px; BORDER-LEFT: #ccdbe4 1px solid; COLOR: #0061de; MARGIN-RIGHT: 3px; PADDING-TOP: 2px; BORDER-BOTTOM: #ccdbe4 1px solid; TEXT-DECORATION: none}";

Result+="\n.pages-nav a:hover { BORDER-RIGHT: #2b55af 1px solid; BORDER-TOP: #2b55af 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #2b55af 1px solid; COLOR: #fff; BORDER-BOTTOM: #2b55af 1px solid; BACKGROUND-COLOR: #3666d4}";

Result+="\n.pages-nav a:active {BORDER-RIGHT: #2b55af 1px solid; BORDER-TOP: #2b55af 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #2b55af 1px solid; COLOR: #fff; BORDER-BOTTOM: #2b55af 1px solid; BACKGROUND-COLOR: #3666d4 }";

Result+="\n.pages-nav SPAN.current {PADDING-RIGHT: 6px; PADDING-LEFT: 6px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; COLOR: #000; MARGIN-RIGHT: 3px; PADDING-TOP: 2px}";

Result+="\n.pages-nav SPAN.default {PADDING-RIGHT: 8px; BACKGROUND-POSITION: 50% bottom; PADDING-LEFT: 8px; PADDING-BOTTOM: 2px;COLOR: #0061de; MARGIN-RIGHT: 3px; PADDING-TOP: 2px;TEXT-DECORATION: none}";

Result+="\n.pages-nav SPAN.disabled {DISPLAY: none}";

Result+="\n.pages-nav input.PageCssInput {BORDER-RIGHT: #ccdbe4 1px solid; PADDING-RIGHT: 8px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #ccdbe4 1px solid; PADDING-LEFT: 8px; PADDING-BOTTOM: 2px; BORDER-LEFT: #ccdbe4 1px solid; COLOR: #0061de; MARGIN-RIGHT: 3px; PADDING-TOP: 2px; BORDER-BOTTOM: #ccdbe4 1px solid; TEXT-DECORATION: none}";
}
else if (Css == "Meneame Style")
{
Result+="\n.pages-nav {PADDING-RIGHT: 3px; PADDING-LEFT: 3px;PADDING-BOTTOM: 3px; MARGIN: 3px; COLOR: #ff6500; PADDING-TOP: 3px; TEXT-ALIGN: " + AlignSorts + " ;clear:both;}";

Result+="\n.pages-nav a {BORDER-RIGHT: #ff9600 1px solid; PADDING-RIGHT: 7px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #ff9600 1px solid; PADDING-LEFT: 7px; BACKGROUND-IMAGE: url(meneame.jpg; PADDING-BOTTOM: 5px; BORDER-LEFT: #ff9600 1px solid; COLOR: #ff6500; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章