62,047
社区成员
发帖
与我相关
我的任务
分享
<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>
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
}
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;
}
}