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
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'/>
5 Comments
Jawad
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
codeandcloud
what element is
builder exactly?Jawad
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>");
Jawad
StringBuilder questionOption = new StringBuilder(); i append html in this. now i want to style this.how?
Erre Efe
@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.
builder.Append("<div class=\"~PLACEHOLDER~\"><table> ....... </table></div>");
Then later in your code
string markup = builder.ToString().Replace("~PLACEHOLDER~", "cssClassName");
3 Comments
Chris
Why are you using a placeholder instead of just putting the classname in straight away?
wonkim00
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.
Chris
Ah, that makes sense. Not as crazy as I first thought. :)