Repeater后台合并单元格问题
前台绑定代码
这个repeater自己写了一个方法想进行合并单元格
老大要求用后台,前台不用说了,GridView我也会,悲催。。。。。。。。
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#bed6e0" id="repeaterTable">
<cc1:HHRepeater ID="repXmxx" runat="server">
<HeaderTemplate>
<tr>
<td nowrap class="number" style="width: 10%" height="25" align="center">
<cc1:HHRepeaterHead ID="HHRepeaterHead4" AllowSort="true" SortExpression="CName"
Text="绑定列头" runat="server"></cc1:HHRepeaterHead>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="whitetd" height="24" id='<%#Eval("itemcode") %>' >
<td align="center">
<asp:Literal ID="litCompany" runat="server"></asp:Literal>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</cc1:HHRepeater>
<asp:HiddenField ID="SelectRowId" runat="server" />
</table>
这个repeater自己写了一个方法想进行合并单元格
public class HHRepeater : Repeater
{
#region 合并单元格
private int[] mergecolumn = null;
/// <summary>
/// 需要合并列的索引
/// </summary>
public int[] MergeColumn
{
get { return mergecolumn; }
set { mergecolumn = value; }
}
private string[] mergeColContorlName = null;
/// <summary>
/// 需要合并列的控件名称(模板列)
/// </summary>
public string[] MergeColContorlName
{
get { return mergeColContorlName; }
set { mergeColContorlName = value; }
}
/// <summary>
/// 绑定数据源后分组合并
/// </summary>
public void DataBindAndGroup()
{
this.DataBind();
if (mergecolumn != null)
GroupRows(mergecolumn);
}
/// <summary>
/// 合并GridView列中相同的行(Add By Caochen)
/// </summary>
/// <param name="MergeColumn">需要合并列的字符串(1,2,3)</param>
private void GroupRows(int[] MergeColumn)
{
int i = 0, rowSpanNum = 1;
for (++i; i < this.Items.Count; i++)
{
RepeaterItem rItem = this.Items[i-1];
RepeaterItem rItemPrevious = this.Items[i];
for (int col = 0; col < MergeColumn.Length; col++)
{
if (!string.IsNullOrEmpty(mergeColContorlName[col]))
{
ITextControl control = rItem.FindControl(mergeColContorlName[col]) as ITextControl;
ITextControl controlPrevious = rItemPrevious.FindControl(mergeColContorlName[col]) as ITextControl;
if (control != null && controlPrevious != null)
{
if (control.Text.Trim() == controlPrevious.Text.Trim())
{
HtmlTableCell oCell = rItem.FindControl(mergeColContorlName[col]) as HtmlTableCell;
HtmlTableCell oCellPrevious = rItemPrevious.FindControl(mergeColContorlName[col]) as HtmlTableCell;//这里一直都是null,想找到页面的table,请高手指点方法
if (oCellPrevious != null && oCell != null)
{
oCell.RowSpan = (oCell.RowSpan == -1) ? 1 : oCell.RowSpan;
oCellPrevious.RowSpan = (oCellPrevious.RowSpan == -1) ? 1 : oCellPrevious.RowSpan;
if (oCell.InnerText == oCellPrevious.InnerText)
{
oCell.Visible = false;
oCellPrevious.RowSpan += oCell.RowSpan;
}
}
}
}
}
}
}
}
#endregion
}
老大要求用后台,前台不用说了,GridView我也会,悲催。。。。。。。。
...全文
相关推荐
ASP.NET中GridView 重复表格列合并的实现方法
本文通过GridView 和 Repeater 解决有关表格显示数据重复的数据列和并的方法,非常实用,感兴趣的朋友一起看下吧
后台动态创建Repeater并绑定数据
后台动态创建Repeater控件,并绑定数据。
ASP.NET中GridView和Repeater重复数据如何合并
这几天做一个项目有用到表格显示数据的地方,客户要求重复的数据列需要合并,就总结了一下GridView 和 Repeater 关于重复数据合并的方法。 效果图如下 : GridView : 前台代码 : <div> <asp ID=gvIncome runat=server AutoGenerateColumns=False> <Columns> <asp HeaderText=一级> <ItemTemplate> <asp:Label ID=Label0 runat=serve
Repeater示例
Repeater基本使用方法示例,包括编辑、删除、更新、分页功能,其中编辑和删除页面名称为EditPage。
嵌套repeater示例分享
主要介绍了嵌套repeater示例,代码简单,下面直接上代码,需要的朋友可以参考下


