简体   繁体   中英

Show LiteralControl in GridView dynamically

I create an html and set it to a literalControl. Then I'm trying to insert this literalControl in a repeater's ItemTemplate.

But when I do this, it is seen as "System.Web.UI.LiteralControl" text, not the html inside.

Here's the code:

<asp:Repeater>
    //SomeColumns
    <ItemTemplate>
        <%# GetPriorityBox(DataBinder.Eval(Container.DataItem, "StartDate"),
                           DataBinder.Eval(Container.DataItem, "EndDate") %>
    </ItemTemplate>
</asp:Repeater>

It is seen from the browser like:

SomeColumn | SomeColumn | System.Web.UI.LiteralControl

Add a .Text to the end of that statement... it won't inject a control using <%# %> notation. It will only inject markup, so you have to inject the text only. If you want the control injected, tap into ItemDataBound event, and programmably add the control.

HTH.

Just add the markup directly to the ItemTemplate. Change your GetPriorityBox method to return the Text property of the LiteralControl.

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