Monday, March 11, 2013

Merge cell in radgrid

protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
                      for (int rowIndex =  RadGrid1.Items.Count - 2; rowIndex >= 0; rowIndex--)
        {
            GridDataItem row =  RadGrid1.Items[rowIndex];
            GridDataItem previousRow =  RadGrid1.Items[rowIndex + 1];

            for (int cellIndex = 0; cellIndex < row.Cells.Count; cellIndex++)
            {
                if (row.Cells[cellIndex].Text == previousRow.Cells[cellIndex].Text)
                {
                    row.Cells[cellIndex].RowSpan = previousRow.Cells[cellIndex].RowSpan < 2 ? 2 :              previousRow.Cells[cellIndex].RowSpan + 1;
                    previousRow.Cells[cellIndex].Visible = false;
                }
            }
        }
    }

No comments:

Post a Comment