C#, ASP.NET, VS08, using HTML table.
I want to merge cells – rowspan and colspan spans it but does not merge it.
For a clear picture,
- drag a HTML table control on the design view
- select the cells of a column
- right click, modify, merge
I would like to do this programatically in C# coding on a button click.
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).
It is similar for rowspan.
Here is an example of a larger merge involving both rowspan and colspan:
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!