0

I want to to create a table with 2 colums in a row. Then in the next row I want only 1 colum. Here is a part of my code:

writer.WriteBeginTag("table");
writer.Write(HtmlTextWriter.TagRightChar);

//first row
writer.WriteFullBeginTag("tr");
writer.WriteBeginTag("td");
writer.WriteAttribute("valign", "top");
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write("row 1, column 1");
writer.WriteEndTag("td");

writer.WriteBeginTag("td");
writer.WriteAttribute("valign", "top");
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write("row 1, column 2");
writer.WriteEndTag("td");
writer.WriteEndTag("tr");

//second row  
writer.WriteFullBeginTag("tr");
writer.WriteBeginTag("td");
writer.WriteAttribute("valign", "top");
writer.WriteAttribute("colspan", "2");
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write("row 2, 1 column");
writer.WriteEndTag("td");
writer.WriteEndTag("tr");

writer.WriteEndTag("table");

Problem is dat the second row is rendered in 1 column, not in 2 columns. This is the outputted html

<tr>
<td valign="top">Check-out date</td>
<td valign="top">Sunday, March 18, 2012</td>
</tr>
<tr>
<td valign="top">You have indicated .... and badge.</td>
</tr>

I guess this is wrong:

writer.WriteAttribute("colspan", "2");

Does somebody know a solution?

Roger
  • 1,004
  • 2
  • 12
  • 24
  • What's with all the `writer.Write(HtmlTextWriter.TagRightChar);`??? Did you look at the HTML that's been output? Can you post that? – Oded Feb 23 '12 at 13:48
  • You can use designer to create tables or u can use table control why this much headache – Prabhavith Feb 23 '12 at 13:54
  • @Oded There were other attributes before writer.Write(HtmlTextWriter.TagRightChar); , which I had deleted for the sample code. The generated output is fine except for the problem that I mentioned. – Roger Feb 23 '12 at 13:55
  • Please post the output you are getting so we can see what is going on. – Oded Feb 23 '12 at 13:57
  • @Prabhavith Yes, I know. I am building a HTML email in a class library project. The class library is referenced in a webforms project. – Roger Feb 23 '12 at 13:57
  • I don't see the `colspan` attribute in the output. – Oded Feb 23 '12 at 14:04
  • @Oded, that is the problem. It is not generated. – Roger Feb 23 '12 at 14:08
  • Have you stepped through your code? Do you see that line being hit? – Oded Feb 23 '12 at 14:10
  • @Oded Yes, after your suggestion I did. On my local machine the colspan attribute was generated. So I deployed the dll to the webserver and I works there as well. Can't explain what went wrong.... Maybe it is just me.. not thinking about stepping through the code! I guess I am little tired and shoudl take a break! Many thanks for helping!! – Roger Feb 23 '12 at 14:29

1 Answers1

1

Try putting the writer.AddAttribute("colspan", "2"); before the td tag on the second row.

TomServo
  • 7,248
  • 5
  • 30
  • 47
Rohlex32
  • 120
  • 9