本来是不想写这篇的,不过由于之前的分页控件样式存在问题,现在更正了,所以还是找点内容发一下。

在封装还存在设计时出错的问题,和repeater一样的写法却设计时不支持,水平不够啊。

后来搞了个笨的方法在DesignMode下输出一段,真是有点,不过不会影响运行时。

<hxj:PageDataList ID="PageDataList1" runat="server" PageIndexBox="DropDownList" 
RepeatColumns="4" PageSize="8" BackColor="White" BorderColor="#DEDFDE"
BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black"
GridLines="Vertical" PageAlign="right" Width="100%" EnableViewState="false">
<FooterStyle BackColor="#CCCC99" />
<ItemStyle BackColor="#F7F7DE" />
<ItemTemplate>
ProductID:
<%
   1: # Eval("ProductID")
%>
<br />
ProductName:
<%
   1: # Eval("ProductName")
%>
</ItemTemplate>
<SelectedItemStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingItemStyle BackColor="White" />
</hxj:PageDataList>

 

设计时效果:

image

本来设计一直出错,技术不够只有多些了一段代码才不好看的解决,如下代码:

base.Render(writer);
if (!DesignMode)
pagerHelper.Render(writer);
else
{
if (!string.IsNullOrEmpty(PageCssClass))
{
writer.AddAttribute(HtmlTextWriterAttribute.Class, PageCssClass);
}
else
{
writer.AddAttribute(HtmlTextWriterAttribute.Class, "pagedefault");
}
if (!string.IsNullOrEmpty(PageStyle))
{
writer.AddAttribute(HtmlTextWriterAttribute.Style, PageStyle);
}
writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, PageAlign.ToString());
writer.AddAttribute(HtmlTextWriterAttribute.Id, UniqueID + "div");
writer.RenderBeginTag(HtmlTextWriterTag.Div);

writer.Write(string.Concat("第", CurrentPageIndex.ToString(), "/", PageCount.ToString(), "页,每页", PageSize.ToString(), "条,共", RecordCount.ToString(), "条 &nbsp;&nbsp;&nbsp;&nbsp;"));

writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.Write("<<");
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.Write("<");
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.Write("1");
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.Write(">");
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.Write(">>");
writer.RenderEndTag();

if (PageIndexBox == PageIndexBoxType.TextBox)
{
writer.AddAttribute(HtmlTextWriterAttribute.Id, UniqueID + "_input");
writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID + "_input");
writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "30px");
writer.AddAttribute(HtmlTextWriterAttribute.Value, CurrentPageIndex.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();

writer.AddAttribute(HtmlTextWriterAttribute.Id, UniqueID + "_btn");
writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID + "_btn");
writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
writer.AddAttribute(HtmlTextWriterAttribute.Value, "Go");
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
}
else if (PageIndexBox == PageIndexBoxType.DropDownList)
{
writer.Write(" 转到第");
writer.AddAttribute(HtmlTextWriterAttribute.Id, UniqueID + "_input");
writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID + "_input");
writer.RenderBeginTag(HtmlTextWriterTag.Select);
for (int i = 1; i <= PageCount; i++)
{
writer.AddAttribute(HtmlTextWriterAttribute.Value, i.ToString());
if (i == CurrentPageIndex)
{
writer.AddAttribute(HtmlTextWriterAttribute.Selected, "true");
}
writer.RenderBeginTag(HtmlTextWriterTag.Option);
writer.Write(i.ToString());
writer.RenderEndTag();
}
writer.RenderEndTag();
writer.Write("页");
}

writer.RenderEndTag();
}

导致下else下面这么长一段代码多出来,不过不影响运行时。

 

CS代码:

protected void Page_Load(object sender, EventArgs e)
{

}

protected void Page_PreRender(object sender, EventArgs e)
{
    PageDataList1.FromSection = DbSession.Default.From<Products>().OrderBy(Products._.ProductID.Asc);
    PageDataList1.DataBind();
}

 

运行时如下:

image

默认样式也修改了,之前的分页控件输出存在问题,导致样式不能发挥作用。

 

样式:PageCssClass=“badoo”

image

 

样式:PageCssClass=“scott”

 

image

各种样式css见 第五节 ,有20多种分页样式。

 

 

下载

posted on 2010-05-08 17:50  steven hu  阅读(1256)  评论(5编辑  收藏  举报