简体   繁体   中英

Add a em tag inside table header cell dynamically in Asp.net

I have a table in my code. The table headers are decide dynamically The heder is for textbox column.

var thc = new TableHeaderCell { Text = "Iteration", CssClass = "iteration" }

I have to change the logic of how the label should be displayed to indicate the textbox entry is mandatory or not.

<em id="lblIterationMandatory" runat="server" class="mandatoryIndicator"
                                                style="display: none;">*</em>

I want to add a * star to the headercell if the text box value is mandatory whose css is defined mandatory Indicator class. My output should be Iteration(black) *(red color,bold).

var thc= new TableHeaderCell { Text = @"Iteration <em id='Iteration' runat='server' class='mandatoryIndicator'                                                 style='display: none;'>*</em>", CssClass = "iteration" };

I tried this way. But * will not be dsiplayed. Since both Iteration and * are different color I think i have to use a separte control for *.

User InnerHtml instead of Text

var thc= new TableHeaderCell { InnerHtml= @"Iteration <em id='Iteration' runat='server' class='mandatoryIndicator'                                                 style='display: none;'>*</em>", CssClass = "iteration" };

also using style='display: none;' will hide any thing on the browser on which it is written.

您将em的显示设置为none将其更改为block

var thc= new TableHeaderCell { Text = @"Iteration <em id='Iteration' runat='server' class='mandatoryIndicator' style='display: block;'>*</em>", CssClass = "iteration" };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM