It's just a little tedious to do this from code-behind, but the process is simple.
First off, I'm assuming your table and its elements are marked with the runat="server"
attribute. This will give you access to the control's server-side API.
Say you want to merge two cells in the first row. The process involves setting the colspan of one cell, then removing the other(s).
myTable.Rows[0].Cells[i].ColSpan = 2;
myTable.Rows[0].Cells.RemoveAt(i + 1)
It is similar for rowspan.
myTable.Rows[0].Cells[i].RowSpan = 2;
myTable.Rows[1].Cells.RemoveAt(i)
Here is an example of a larger merge involving both rowspan and colspan:
myTable.Rows[0].Cells[i].ColSpan = 2;
myTable.Rows[0].Cells[i].RowSpan = 2;
myTable.Rows[0].Cells.RemoveAt(i + 1)
myTable.Rows[1].Cells.RemoveAt(i)
myTable.Rows[1].Cells.RemoveAt(i + 1)
Note that if your table already has row spans and cell spans that you will have more footwork to do to calculate which cells need removing.
Good luck!