0

i created a html div tags that hold table in which data is coming from database via function. this html code i have written in code behind c# file. i want to apply css on div tag that written in code behind file how?

2 Answers 2

2

Just make your code generate something like:

<div id="div" style="left: 327px; top: 9px; width: 323px; height: 138px"> </div>

Replace style with your custom css.

Or, if you have it declared on an external css file, then use:

<div id="div" class='cssClassName'/>
Sign up to request clarification or add additional context in comments.

5 Comments

No you are not getting my point. html in dynamically created in code behind file. i want to apply css on in. the code is like this builder.Append("<div><table> ....... </table></div>"); i want to apply css class on div tag
what element is builder exactly?
questionOption.Append("<tr><td><input type=\"checkbox\" onclick=\"save_mcma_answer(this)\"" + " name=\"" + optionID + "\" id=\"" + optionID + "\"/></td>"); questionOption.Append("<td>" + optionText + "</td>"); this is my code in C# code behind file. i have external css class. i want to style these type of tags or element. questionOption.Append("</tr>");
StringBuilder questionOption = new StringBuilder(); i append html in this. now i want to style this.how?
@Jawad, as Randolf suggested you, use the class attribute in your code behind to apply styles. It doesn't mind if its being generated. For example, use: questionOption.Append("<td CLASS='OPTION_TEXT_CSS_STYLE'>" + optionText + "</td>"); given that you have that CSS class declared on your external css.
1
builder.Append("<div class=\"~PLACEHOLDER~\"><table> ....... </table></div>");

Then later in your code

string markup = builder.ToString().Replace("~PLACEHOLDER~", "cssClassName");

3 Comments

Why are you using a placeholder instead of just putting the classname in straight away?
It seemed like the OP wanted some way to modify the div tag after having already committed it to the string. I could be wrong on that point, and you're right -- simply adding the correct classname to the div tag is the simplest and most straightforward solution, if the classname is known at that point.
Ah, that makes sense. Not as crazy as I first thought. :)

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.