开发者

How to add css style/class to a HtmlTextWriterTag.Td dynamically in .net?

I have the following c# code in my control's RenderContents method. How can I add the style/class that is in external css file?

output.AddAttribute(HtmlTextWriterAttribute.Border, "0");
output.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
output.RenderBeginTag(HtmlTextWriterTag.Table);
output.RenderBeginTag(HtmlTextWri开发者_开发百科terTag.Tbody);
output.RenderBeginTag(HtmlTextWriterTag.Tr);
//Here -> Need to add some style from external stylesheet.css file
output.RenderBeginTag(HtmlTextWriterTag.Td);
rblLoadSelection.RenderControl(output);
output.RenderEndTag(); //Td
output.RenderEndTag(); //Tr
output.RenderEndTag(); //Tbody
output.RenderEndTag(); //Table


You shouldn't reference an external stylesheet between a td and tr. The best place to put it is in the head tag of your document.

Based on your comments, if you just need to add a class to td, do this:

output.AddAttribute(HtmlTextWriterAttribute.Class, "myclass");


I dont think you can include external CSS (without including it in head and use classes) or do it inline like this:

output.AddStyleAttribute(HtmlTextWriterStyle.Color, "#000000");
output.RenderBeginTag(HtmlTextWriterTag.Td);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜