我想创建一个一行有2列的表。然后在下一排,我只想要一列。这是我代码的一部分:
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");
问题是第二行是在1列中呈现的,而不是在2列中。这是输出的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>
我想这是错误的:
writter.WriteAttribute("colspan","2");
有人知道解决方案吗?
尝试将writer.AddAttribute("colspan", "2");
放在第二行的td
标记之前。