gridview合并相同行请教!
请教下高手如何合并gridview相同行?
结果像这样的?
谢谢!~
------解决方案--------------------GridView嵌套!!
------解决方案--------------------用模板列,自定义绑定方式可以做到
------解决方案--------------------报表工具可以实现
,也可以在数据库中处理
------解决方案--------------------用这个
public void mergetable(string console)
{
for (int i = ProductList.Items.Count - 1; i > 0; i--)
{
HtmlTableCell oCell_previous = ProductList.Items[i - 1].FindControl(console) as HtmlTableCell;
HtmlTableCell oCell = ProductList.Items[i].FindControl(console) as HtmlTableCell;
oCell.RowSpan = (oCell.RowSpan == -1) ? 1 : oCell.RowSpan;
oCell_previous.RowSpan = (oCell_previous.RowSpan == -1) ? 1 : oCell_previous.RowSpan;
if (oCell.InnerText == oCell_previous.InnerText)
{
oCell.Visible = false;
oCell_previous.RowSpan += oCell.RowSpan;
}
}
}
调用方法
protected void ProductList_PreRender(object sender, EventArgs e)
{
mergetable("leixing");
mergetable("pinpai");
}
前面aspx
<asp:Repeater ID="ProductList" runat="server" OnPreRender="ProductList_PreRender" OnItemDataBound="ProductList_ItemDataBound">
<ItemTemplate>
<tr>
<td align="center" valign="middle" bgcolor="#FFFFFF" id="leixing" runat="server"><%#Eval("brandname") %></td>
<td align="center" valign="middle" bgcolor="#FFFFFF" id="pinpai" runat="server"><%#Eval("producttypename") %></td>
<td align="left" valign="middle" bgcolor="#FFFFFF"><a href='<%#"jieshao.aspx?id="+Eval("id") %>' target="_blank"><%#Eval("name") %></a> </td>
<td align="center" valign="middle" bgcolor="#FFFFFF">
<div style="margin-top:-20px;"><table width="100" border="0" cellpadding="1" cellspacing="0">
<tr>
<td width="95" align="center" valign="top"><img src="../images/line.gif" width="45" height="1" alt="line" /></td>
<td width="25" rowspan="2" align="center" valign="top" id="pdf"><asp:Literal ID="pdfurl" runat="server"></asp:Literal></td>
</tr>
<tr>
<td align="center" valign="top" id="tuxiang"><input type="hidden" id="hiddenid" value='<%#Eval("id") %>' runat="server" /><input type="hidden" id="hiddenname" value='<%#Eval("name") %>' runat="server" />
<asp:Literal ID="picurl" runat="server"></asp:Literal> </td>
</tr>
</table>
</div>
</td>