Repeater05-Repeater重复数据的合并
来源:互联网 发布:有什么供应商软件 编辑:程序博客网 时间:2024/05/14 07:11
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RepeaterToRow2.aspx.cs" Inherits="RepeaterToRow2" %><%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style> #tablePrint { width: 100%; margin-bottom: 5px; } #tablePrint, #tablePrint th, #tablePrint td { border: 1px solid #ccc; border-collapse: collapse; padding: 2px; } #tablePrint tr:nth-child(odd) { background-color: rgb(235, 240, 255); } </style></head><body> <form id="form1" runat="server"> <div> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table id="tablePrint" class="tbShow"> <tr class="th"> <td nowrap width="35px;" align="center">序号</td> <td nowrap>学校</td> <td nowrap>班级</td> <td nowrap>姓名</td> <td nowrap>性别</td> <td nowrap>手机</td> <td nowrap>邮箱</td> </tr> </HeaderTemplate> <ItemTemplate> <tr id="trIdrep" onmouseover="this.bgColor='#C4DFF7'" onmouseout="this.bgColor='#ffffff'"> <td nowrap id="td0" runat="server"><%#Container.ItemIndex+1%> </td> <td nowrap id="td1" runat="server"><%#Eval("userSchool")%></td> <td nowrap id="td2" runat="server"><%#Eval("userClass")%></td> <td nowrap id="td3" runat="server"><%#Eval("userName")%></td> <td nowrap id="td4" runat="server"><%#Eval("userSex")%></td> <td nowrap id="td5" runat="server"><%#Eval("userPhone")%></td> <td nowrap id="td6" runat="server"><%#Eval("userEmail")%></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> </div> </form></body></html>
后台代码:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.Web.UI.HtmlControls;public partial class RepeaterToRow2 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataBindRepeater(); } } private void DataBindRepeater() { string strSql = "select * from UserInfo"; DataSet ds = SqlHelper.ExecuteDataset(CommandType.Text, strSql); this.Repeater1.DataSource = ds.Tables[0]; this.Repeater1.DataBind(); for (int i = 0; i < 7; i++) // 遍历每一列 { string tdTd = "td"; string tdIdName = tdTd + i.ToString(); MergeCell(tdIdName); // 把当前列的td的ID文本作为方法的参数 } } /// <summary> /// /// </summary> /// <param name="tdIdName">当前列当前行的 td 的ID文本</param> private void MergeCell(string tdIdName) { for (int i = Repeater1.Items.Count - 1; i > 0; i--) // Repeater1.Items.Count - 1 数据总行数(数据从0开始) 遍历当前列的每一行 { MergeCellSet(tdIdName, i); } } /// <summary> /// /// </summary> /// <param name="tdIdName1">当前列当前行的 td 的ID文本</param> /// <param name="i">当前行</param> private void MergeCellSet(string tdIdName1, int i) { HtmlTableCell cellPrev = Repeater1.Items[i - 1].FindControl(tdIdName1) as HtmlTableCell; // 获取下一行当前列的 td 所在的单元格 HtmlTableCell cell = Repeater1.Items[i].FindControl(tdIdName1) as HtmlTableCell; // 获取当前行当前列的 td 所在的单元格 cell.RowSpan = (cell.RowSpan == -1) ? 1 : cell.RowSpan; // 获取当前行当前列单元格跨越的行数 cellPrev.RowSpan = (cellPrev.RowSpan == -1) ? 1 : cellPrev.RowSpan; // 获取下一行当前列单元格跨越的行数 if (cell.InnerText == cellPrev.InnerText) { // 让下一行的当前单元格的跨越行数 + 当前行的跨越行数 cellPrev.RowSpan += cell.RowSpan; cell.Visible = false; // 隐藏当前行 //关键代码,再判断执行第2列的合并单元格方法 } }}
页面展示:
注意要点:
之前的案例是某列的重复数据的合并,而此案例则是将整个Repeater都进行重复数据合并,就是对之前的方法加上循环。
前台注意的就是命名ID时从0开始命名,并加上服务器标志,在后台的话,则是循环时的列数需要注意。
0 0
- Repeater05-Repeater重复数据的合并
- Repeater04-Repeater某列重复数据的合并
- 对绑定到repeater控件的数据消除重复行
- 动态合并Repeater控件数据列
- DataSet的简单合并和DataTable的重复数据过滤
- 合并重复数据并求和
- ThinkPHP去除重复数据 合并重复字段
- 两个ArrayList合并,并且去掉重复数据的算法
- java两个ArrayList合并,并且去掉重复数据的算法
- 两个ArrayList合并,并且去掉重复数据的算法
- 合并两个有序的数列并删除重复数据
- 通过js合并表格重复出现的数据
- 怎样合并repeater中相同的行
- Repeater 合并相同值的单元格
- Repeater数据控件的嵌套
- 删除一个表中与另一个表主键重复的数据 然后将俩个表的数据合并
- repeater纵向重复显示数据,即第一列为字段,第二、三、四。。列重复显示数据
- 合并重复的条件片段
- uva10294 Arif in Dhaka (First Love Part 2)
- 非对称加密和加密算法
- CNN+caffe学习3:data processing
- opencv在vs2013的环境配置
- Okhttp实践
- Repeater05-Repeater重复数据的合并
- JAVA-注解学习
- 如何将mxd文档直接发布为ArcGIS Server服务
- maven 的常用命令
- mongodb
- 抛出Activity did not call through to super.onDestroy()的解决方案
- AndroidFix热修复例子
- Hive over HBase和Hive over HDFS性能比较分析
- 【Get深一度】相位差&波束指向角推导-相控阵雷达原理