protected void GridView1_DataBound(object sender, EventArgs e)
{
int row=0;
for (int i = 1; i < GridView1.Rows.Count; i++)
{
if (GridView1.Rows[i].Cells[0].Text == GridView1.Rows[i - 1].Cells[0].Text)
{
if (GridView1.Rows[row].Cells[0].RowSpan == 0) GridView1.Rows[row].Cells[0].RowSpan++;
GridView1.Rows[row].Cells[0].RowSpan++;
GridView1.Rows[i].Cells[0].Visible = false;
}
else
{
row = i;
}
}
后台代码输入以上内容。
<asp:GridView ID="GridView1" runat="server" OnDataBound="GridView1_DataBound">
</asp:GridView>
前台页面GridView1中添加
OnDataBound="GridView1_DataBound"
这样就可以实现列中相同信息的行合并了。