开发者

asp:Literal databinding idiosyncrasies

I have a website that relies heavily on a Creole parser for allowing wiki formatting in several areas of the site (the wiki itself, the forum, etc.)

In the wiki,Ii use a Literal control to display the rendered text (that contains actual HTML elements rendered from the original creole text). The code is basically as follows:

<asp:literal id="renderedText" runat="server" />

----

string creoleText = db.GetTable<Wiki>().Where(w => w.ID == id).Single().CreoleText;

RenderEngine engine = new RenderEngine();
renderedText.Text = engine.Render(creoleText);

and everything works just fine.

However, trying to accomplish the same thing via data binding and using an asp:Repeater, I can't seem to get the text to render. Basically I'm doing this:

<asp:repeater id="conversationRepeater" runat="server">

<!-- header template, itemtemplate, etc -->

 <tr><td>
 <asp:literal runat="server"
  text='&开发者_运维技巧lt;%# DataBinder.Eval(Container.DataItem, "Content") %>' />
 </td></tr>

----

RenderEngine engine = new RenderEngine();

var forumConversation = db.GetTable<ThreadMessage>()
    .Select(t => new ThreadMessage
        {
            ID = t.ID,
            Content = engine.Render(t.Content)
        }
    );

conversationRepeater.DataSource = forumConversation;
conversationRepeater.DataBind();

and I just end up with the original creole text, not the rendered text with actual HTML elements that I need.


Figured I'd post the solution I went with. It was quite simple really. I just create a static version of my Render Engine and in it, created an extension method that I could use in my databinding expressions:

<%# ((string)DataBinder.Eval(Container.DataItem, "WikiText"))).Render() %>

Done.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜