repeater创建复杂的表头

Repeater创建复杂表头的表格 文章指数:0 CSDN Blog推出文章指数概念,文章指数是对Blog文章综合评分后推算出的,综合评分项分别是该文章的点击量,回复次数,被网摘收录数量,文章长度和文章类型;满分100,每月更新一次。
GridView的功能虽然强大,但在创建复杂表头报表时却显得逊色许多。此时我们应该想起另外一个控件:Repeater。下面是Repeater的结构:

//QQ:272912705 光之翼 www.hi.baidu.com/jcomet
<asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate>
    </HeaderTemplate>
    <ItemTemplate>
    </ItemTemplate>
    <AlternatingItemTemplate>
    </AlternatingItemTemplate>
    <FooterTemplate>
    </FooterTemplate>
</asp:Repeater>
顾名思义,HeaderTemplate为表头模板,ItemTemplate为可重复的项,AlternatingItemTemplate为可重复交替项,FooterTemplate为注脚部部分。
下面给出示例:

1. 前台代码:
<asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate>
        <table border="1" align="center" width="100%" bordercolorlight="#a9a9a9" bordercolordark="#ffffff"
            cellspacing="0" cellpadding="1" bordercolor="#a9a9a9" style="text-align: center;">
            <tr bgcolor="#B5DBFF">
                <td rowspan="2" style="width: 100px">
                    波段</td>
                <td rowspan="2" style="width: 100px">
                    时段</td>
                <td colspan="3" style="height: 17px;">
                    第一部分</td>
                <td colspan="3" style="height: 17px;">
                    第二部分</td>
                <td rowspan="2" style="width: 100px">
                    合计</td>
            </tr>
            <tr bgcolor="#B5DBFF">
                <td style="width: 100px; height: 17px;">
                    一</td>
                <td style="width: 100px; height: 17px;">
                    二</td>
                <td style="width: 100px; height: 17px;">
                    三</td>
                <td style="width: 100px; height: 17px;">
                    四</td>
                <td style="width: 100px; height: 17px;">
                    五</td>
                <td style="width: 100px; height: 17px;">
                    六</td>
            </tr>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td style="width: 100px">
                <%# Eval("ChannelID") %>
            </td>
            <td style="width: 100px">
                <%# Eval("Time")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Monday")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Tuesday")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Wednesday")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Thursday")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Friday")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Saturday")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Sunday")%>
            </td>
        </tr>
    </ItemTemplate>
    <AlternatingItemTemplate>
        <tr style="background-color: WhiteSmoke;">
            <td style="width: 100px">
                <%# Eval("ChannelID") %>
            </td>
            <td style="width: 100px">
                <%# Eval("Time")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Monday")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Tuesday")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Wednesday")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Thursday")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Friday")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Saturday")%>
            </td>
            <td style="width: 100px">
                <%# Eval("Sunday")%>
            </td>
        </tr>
    </AlternatingItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>
<cc1:WebPager ID="WebPager1" runat="server" PagerStyle="NextPrev" ControlToPaginate="Repeater1"
    ItemsPerPage="24" OnPageIndexChanged="WebPager1_PageIndexChanged" />
2. 后台代码:
Page事件#region Page事件
DataTest.BLL.GetData myBiz = new DataTest.BLL.GetData();
protected void Page_Load(object sender, EventArgs e)
...{
    if (!Page.IsPostBack)
    ...{
        GetData();
        BindGrid();
    }
}
#endregion

Repeater#region Repeater

数据绑定#region 数据绑定
/**//// <summary>
/// 获取数据
/// </summary>
protected void GetData()
...{
    this.DataSource = myBiz.GetOrderDetails("RM_Clocks"); ;
}

/**//// <summary>
/// GridView 数据绑定
/// </summary>
private void BindGrid()
...{
    WebPager1.DataSource = this.DataSource;
    WebPager1.DataBind();
}
#endregion

分页#region 分页
protected void WebPager1_PageIndexChanged(object sender, wf.WebPager.PageChangedEventArgs e)
...{
    WebPager1.CurrentPageIndex = e.NewPageIndex;
    WebPager1.DataSource = this.DataSource;
    WebPager1.DataBind();
}
#endregion

#endregion

posted @ 2008-07-14 14:18  洗碗心得  阅读(359)  评论(0编辑  收藏  举报