views:

37

answers:

0

i am trying to merge similar data together but choosen data. for example the table has 5 rows and i want 3 rows which have similar data to merge. other 2 rows, even though it contains similar data, i dont want it to merge. is there a way to do this?

here is my current code:

        protected void DataBoundModuleGV(object sender, EventArgs e)
    {
        for (int rowIndex = ModuleGV.Rows.Count - 2; rowIndex >= 0; rowIndex--)
        {
            GridViewRow gvCurrRow = ModuleGV.Rows[rowIndex];
            GridViewRow gvPrevRow = ModuleGV.Rows[rowIndex + 1];
            for (int cellCount = 0; cellCount < gvCurrRow.Cells.Count; cellCount++)
            {
                if (gvCurrRow.Cells[cellCount].Text == gvPrevRow.Cells[cellCount].Text)
                {
                    if (gvPrevRow.Cells[cellCount].RowSpan < 2)
                    {
                        gvCurrRow.Cells[cellCount].RowSpan = 2;
                    }
                    else
                    {
                        gvCurrRow.Cells[cellCount].RowSpan = gvPrevRow.Cells[cellCount].RowSpan + 1;
                    }
                    gvPrevRow.Cells[cellCount].Visible = false;
                }
            }
        }
    }

E.G.

class: 1a
studentName: nana
birthday: 29 dec
favouriteColour: red
favouriteFood: fries

class: 1a studentName: banana
birthday: 29 dec
favouriteColour: red
favouriteFood: fries

class: 1a
studentName: canana
birthday:09 jan
favouriteColour: maroon
favouriteFood: fish

class: 2a
studentName: danana
birthday: 09 dec
favouriteColour: maroon
favouriteFood: fries

I want to merge class data into 1 row, so it will show only 1 row of 1a. even though birthday the first and second data is the same, i dont want it to merge and for favouritecolour and favouritefood, i want it to merge if have same data but, although the favourite colour for canana and danana is the same, they shouldnt merge. is this possible?