📄 gridviewpageable.cs
字号:
//str.Append("</script>");
return str.ToString();
}
#endregion
#region 分页栏
/// <summary>
/// 数值按钮
/// </summary>
/// <returns></returns>
private void RenderNumericButton(HtmlTextWriter writer)
{
int i = 10;
//数值按钮当前分页的最后一页索引
int endindex = this.FirstNumericButton + i;
//数值按钮分页最后一面的分页数
int endpage = this.PageViewCount % 10;
if (endpage != 0 && (this.PageViewIndex > (this.PageViewCount - endpage - 1) &&
this.PageViewIndex < this.PageViewCount))
{ //索引页在最后一面分页中
endindex = this.PageViewCount;
}
for (int j = this.FirstNumericButton; j < endindex; j++)
{
if (j == this.PageViewIndex)
{ //当前页
CreateNumericButton(writer, j, false);
}
else
{
CreateNumericButton(writer, j, true);
}
}
}
/// <summary>
/// 创建数值型按钮
/// </summary>
/// <param name="writer">HTML输出流</param>
/// <param name="text">数值按钮文本</param>
private void CreateNumericButton(HtmlTextWriter writer, int text, bool show)
{
writer.Write(" ");
string strtext = string.Format("{0}", text + 1);
if (show == true)
{ //没被选择
writer.AddStyleAttribute(HtmlTextWriterStyle.TextDecoration, "none");
writer.AddAttribute(HtmlTextWriterAttribute.Href, Page.ClientScript.GetPostBackClientHyperlink(this, "pager$" + text.ToString()));
writer.RenderBeginTag(HtmlTextWriterTag.A);
writer.Write(strtext);
writer.RenderEndTag();
}
else
{ //当前被选页面
writer.Write(strtext);
}
writer.Write(" ");
}
/// <summary>
/// 当前页,总页数
/// </summary>
/// <returns></returns>
private string RenderPageNow()
{
string templateCell = string.Format(PageNowFormat, PageViewIndex + 1, PageViewCount);
return templateCell;
}
/// <summary>
/// 每页行数,总行数
/// </summary>
/// <returns></returns>
private string RenderPageRow()
{
string templateCell = string.Format(PageRowFormat, PageViewSize, PageRowCount);
return templateCell;
}
/// <summary>
/// 首页
/// </summary>
/// <returns></returns>
private string RenderFirst()
{
string templateCell = string.Empty;
if (PageButtonType == BUTTON_TYPE.Text)
{
if (PageViewIndex <= 0)
{
templateCell = PageFirstFormat;
}
else
{
templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\">{1}</a>",
Page.ClientScript.GetPostBackClientHyperlink(this, "pager$0"), PageFirstFormat);
}
}
else
{
if (PageViewIndex <= 0)
{
templateCell = string.Format("<img border=\"0\" src=\"{0}\" />", ConverImageUrl(PageFirstImage));
}
else
{
templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\"><img border=\"0\" src=\"{1}\" /></a>",
Page.ClientScript.GetPostBackClientHyperlink(this, "pager$0"), ConverImageUrl(PageFirstImage));
}
}
return templateCell;
}
/// <summary>
/// 末页
/// </summary>
/// <returns></returns>
private string RenderLast()
{
string templateCell = string.Empty;
if (PageButtonType == BUTTON_TYPE.Text)
{
if (PageViewIndex >= PageViewCount - 1)
{
templateCell = PageLastFormat;
}
else
{
templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\">{1}</a>",
Page.ClientScript.GetPostBackClientHyperlink(this, string.Format("pager${0}", PageViewCount - 1)), PageLastFormat);
}
}
else
{
if (PageViewIndex >= PageViewCount - 1)
{
templateCell = string.Format("<img border=\"0\" src=\"{0}\" />", ConverImageUrl(PageLastImage));
}
else
{
templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\"><img border=\"0\" src=\"{1}\" /></a>",
Page.ClientScript.GetPostBackClientHyperlink(this, string.Format("pager${0}", PageViewCount - 1)), ConverImageUrl(PageLastImage));
}
}
return templateCell;
}
/// <summary>
/// 上一页
/// </summary>
/// <returns></returns>
private string RenderBack()
{
string templateCell = string.Empty;
if (PageButtonType == BUTTON_TYPE.Text)
{
if (PageViewIndex <= 0)
{ //当前是第1页
templateCell = PageBackFormat;
}
else
{
templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\">{1}</a>",
Page.ClientScript.GetPostBackClientHyperlink(this, string.Format("pager${0}", PageViewIndex - 1)), PageBackFormat);
}
}
else
{
if (PageViewIndex <= 0)
{ //当前是第1页
templateCell = string.Format("<img border=\"0\" src=\"{0}\" />", ConverImageUrl(PageBackImage));
}
else
{
templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\"><img border=\"0\" src=\"{1}\" /></a>",
Page.ClientScript.GetPostBackClientHyperlink(this, string.Format("pager${0}", PageViewIndex - 1)), ConverImageUrl(PageBackImage));
}
}
return templateCell;
}
/// <summary>
/// 下一页
/// </summary>
/// <returns></returns>
private string RenderNext()
{
string templateCell = string.Empty;
if (PageButtonType == BUTTON_TYPE.Text)
{
if (PageViewIndex >= PageViewCount - 1)
{ //当前是末页
templateCell = PageNextFormat;
}
else
{
templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\">{1}</a>",
Page.ClientScript.GetPostBackClientHyperlink(this, string.Format("pager${0}", PageViewIndex + 1)), PageNextFormat);
}
}
else
{
if (PageViewIndex >= PageViewCount - 1)
{ //当前是末页
templateCell = string.Format("<img border=\"0\" src=\"{0}\" />", ConverImageUrl(PageNextImage));
}
else
{
templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\"><img border=\"0\" src=\"{1}\" /></a>",
Page.ClientScript.GetPostBackClientHyperlink(this, string.Format("pager${0}", PageViewIndex + 1)), ConverImageUrl(PageNextImage));
}
}
return templateCell;
}
#endregion
#region 图片路径转换
private string ResolvePhysicalLocation(string path)
{
ISite site1 = this.GetSite();
if (site1 == null)
{
return path;
}
IWebApplication application1 = (IWebApplication)site1.GetService(typeof(IWebApplication));
IProjectItem item1 = application1.GetProjectItemFromUrl(path);
if (item1 != null)
{
return item1.PhysicalPath;
}
return path.Replace("~/", application1.RootProjectItem.PhysicalPath);
}
private ISite GetSite()
{
if (base.Site != null)
{
return base.Site;
}
for (Control control1 = this.Parent; control1 != null; control1 = control1.Parent)
{
if (control1.Site != null)
{
return control1.Site;
}
}
return null;
}
private void RenderImage(HtmlTextWriter writer, string imageurl)
{
if (this.Page != null)
{
string text1 = this.Page.ResolveUrl(imageurl);
if (base.DesignMode)
{
string text2 = this.ResolvePhysicalLocation(text1);
text1 = text2;
}
writer.AddAttribute(HtmlTextWriterAttribute.Src, text1);
}
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
}
private string ConverImageUrl(string url)
{
string text1 = this.Page.ResolveUrl(url);
return this.ResolvePhysicalLocation(text1);
}
#endregion
#region 回发数据和事件
/// <summary>
/// 数据回发判断
/// </summary>
/// <param name="postDataKey"></param>
/// <param name="postCollection"></param>
/// <returns></returns>
public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
{
string postedValue = postCollection[postDataKey];
string presentValue = Text;
if (presentValue == null || postedValue != presentValue)
{
Text = postedValue;
return true;
}
return false;
}
/// <summary>
/// 数据回发激发事件
/// </summary>
public void RaisePostDataChangedEvent()
{
OnTextChanged(EventArgs.Empty);
}
/// <summary>
/// OnTextChanged事件
/// </summary>
/// <param name="eventArgs"></param>
private void OnTextChanged(EventArgs eventArgs)
{
EventHandler textChangedHandler = (EventHandler)Events[EventTextChanged];
if (textChangedHandler != null)
{
textChangedHandler(this, eventArgs);
}
}
/// <summary>
/// 为TextChanged实现事件属性结构
/// </summary>
public event EventHandler TextChanged
{
add
{
Events.AddHandler(EventTextChanged, value);
}
remove
{
Events.RemoveHandler(EventTextChanged, value);
}
}
/// <summary>
/// 事件回发
/// </summary>
/// <param name="eventArgument"></param>
protected override void RaisePostBackEvent(string eventArgument)
{
base.RaisePostBackEvent(eventArgument);
if (this.AllowPagerable == true)
{
string[] str = eventArgument.Split('$');
if (str[0] == "jump")
{ //跳转按钮
Int32 pi;
try
{
string index = (string)ViewState["Text"];
pi = Int32.Parse(index);
pi -= 1;
}
catch
{
pi = PageViewIndex;
}
if (pi >= 0 && pi <= PageViewCount - 1)
{
PageViewIndex = pi;
}
else
{
PageViewIndex = PageViewCount - 1;
}
OnChangePageIndex(new EventArgs());
}
else if (str[0] == "pager")
{ //文字按钮
PageViewIndex = Int32.Parse(str[1]);
OnChangePageIndex(new EventArgs());
}
if (this.ShowNumericButton == true)
{
if (this.PageViewIndex >= (this.FirstNumericButton + 10))
{ //向后翻页
if (this.PageViewIndex == (this.PageViewCount - 1))
{ //末页
if ((this.PageViewCount % 10) == 0)
{ //每面页数一样
this.FirstNumericButton = this.PageViewIndex - 10 + 1;
}
else
{
this.FirstNumericButton = this.PageViewIndex - (this.PageViewCount % 10) + 1;
}
}
else
{
this.FirstNumericButton = this.PageViewIndex;
}
}
else if (this.PageViewIndex < this.FirstNumericButton)
{ //向前翻页
if (this.PageViewIndex == 0)
{ //首页
this.FirstNumericButton = 0;
}
else
{
this.FirstNumericButton = this.PageViewIndex - 10 + 1;
}
}
OnChangePageIndex(new EventArgs());
}
}
}
/// <summary>
/// 激发页面索引改变
/// </summary>
/// <param name="e"></param>
private void OnChangePageIndex(EventArgs e)
{
ChangePageIndex(this, e);
}
#endregion
#region 输出分页栏
public override void RenderControl(HtmlTextWriter writer)
{
if (BottomPagerRow != null)
{
BottomPagerRow.Cells.Clear();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -