If field data is repeating row wise, when we bind data with Gridview, same record is show more times in Gridview as below.
123456 Commercial Bank PLC
345632 Commercial Bank PLC
378912 Commercial Bank PLC
I am going to show one record for repeating data as below.
123456
345632 Commercial Bank PLC
378912
As previous articles we have to drag and drop Griview controller to design form and bind data using data source.
Open the Gridview RoDataBound event and past the below coding
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int rowIndex = GridView1.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow row = GridView1.Rows[rowIndex];
GridViewRow previousRow = GridView1.Rows[rowIndex + 1];
if (row.Cells[1].Text == previousRow.Cells[1].Text)
{
row.Cells[1].RowSpan = previousRow.Cells[1].RowSpan < 2 ? 2 :
previousRow.Cells[1].RowSpan + 1;
previousRow.Cells[1].Visible = false;
}
}
}
{
for (int rowIndex = GridView1.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow row = GridView1.Rows[rowIndex];
GridViewRow previousRow = GridView1.Rows[rowIndex + 1];
if (row.Cells[1].Text == previousRow.Cells[1].Text)
{
row.Cells[1].RowSpan = previousRow.Cells[1].RowSpan < 2 ? 2 :
previousRow.Cells[1].RowSpan + 1;
previousRow.Cells[1].Visible = false;
}
}
}
I have explain this Gridview cell merge with VB also Click hear
0 comments:
Post a Comment