开发者

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 ItemTempl开发者_开发知识库ate.

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


Just add the markup directly to the ItemTemplate. Change your GetPriorityBox method to return the Text property of the 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜