码迷,mamicode.com
首页 > 其他好文 > 详细

Repeater 创建复杂表头的表格

时间:2014-07-28 14:58:33      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   数据   io   art   

Repeater 创建复杂表头的表格 

2008-06-05 15:00:46|  分类: 每日技术 |  标签: |举报 |字号 订阅

 
 

GridView的功能虽然强大,但在创建复杂表头报表时却显得逊色许多。此时我们应该想起另外一个控件:Repeater。下面是Repeater的结构: <asp:Repeater ID="Repeater1" runat="server">     <HeaderTemplate>     </HeaderTemplate>     <ItemTemplate>     </ItemTemplate>     <AlternatingItemTemplate>     </AlternatingItemTemplate>     <FooterTemplate>     </FooterTemplate> </asp:Repeater> 顾名思义,HeaderTemplate为表头模板,ItemTemplate为可重复的项,AlternatingItemTemplate为可重复交替项,FooterTemplate为注脚部部分。
下面给出示例:

 

bubuko.com,布布扣

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="">             <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. 后台代码: #region Page事件 DataTest.BLL.GetData myBiz = new DataTest.BLL.GetData(); protected void Page_Load(object sender, EventArgs e) {     if (!Page.IsPostBack)     {         GetData();         BindGrid();     } } #endregion

#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

Repeater 创建复杂表头的表格,布布扣,bubuko.com

Repeater 创建复杂表头的表格

标签:style   blog   http   color   os   数据   io   art   

原文地址:http://www.cnblogs.com/baidong/p/3872711.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!