如何在.net中动态地将css样式/类添加到HtmlTextWriterTag.Td?
我的控件的 RenderContents 方法中有以下 C# 代码。如何添加外部 css 文件中的样式/类?
output.AddAttribute(HtmlTextWriterAttribute.Border, "0");
output.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
output.RenderBeginTag(HtmlTextWriterTag.Table);
output.RenderBeginTag(HtmlTextWriterTag.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
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(HtmlTextWriterTag.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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应在
td
和tr
之间引用外部样式表。放置它的最佳位置是文档的head
标记中。根据您的评论,如果您只需要向 td 添加一个类,请执行以下操作:
You shouldn't reference an external stylesheet between a
td
andtr
. The best place to put it is in thehead
tag of your document.Based on your comments, if you just need to add a class to
td
, do this:我不认为你可以包含外部 CSS(不将其包含在 head 和 use 类中)或像这样内联:
I dont think you can include external CSS (without including it in head and use classes) or do it inline like this: