1

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

2 Answers 2

2

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");
Sign up to request clarification or add additional context in comments.

2 Comments

I think he wants to add a style, or class attribute to the TD element, not a link to a stylesheet (I think).
yes, I just need to add a style/class to TD. Sorry for the not being clear.
1

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);

1 Comment

I need to add the css style class to td not add an external css file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.