Nesting in a ListView control does not display code

CodeHighlighter for ASP.NET Forum

Posted 16 years ago by TimothyP
Version: 4.0.51
Avatar
Hello,

I'm trying to nest the SyntaxHighlighter Control in a ListView
The ListVIew is bound to a LinqDataSource

The first problem is that while the ListView works
and multiple syntaxhighlighter controls are created,
the code in the control is simply not being displayed.

The second problem is more of a question than a real problem
LanguageKey=<%# Eval("Language") %>

Language in the database contains "C#" for example
But that is not allowed by ASP.NET, any workarounds?


Thank you.

Comments (6)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
For the first issue, I'm not sure what would cause it not to output anything unless somehow you weren't populating the input to the control properly. Maybe try hardcoding input to see if it makes any output.

For the second, try putting single quotes around the <%...%>.


Actipro Software Support

Posted 16 years ago by TimothyP
Avatar
Hi,

The language problem seems to be solved.


This is the code for my ListView and data source:

<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id"
    DataSourceID="CodeSamplesDataSource" onitemcreated="ListView1_ItemCreated">

    <LayoutTemplate>
        <div ID="itemPlaceholder" runat="server"></div>
    </LayoutTemplate>
    <ItemTemplate>
    <pre>
        <cc1:CodeHighlighter ID="codeHighlighter" 
                     runat="server" 
                     LanguageKey='<%# Eval("Language") %>'>
            <%# Eval("Body") %>
        </cc1:CodeHighlighter>
    </pre>
    </ItemTemplate>
   
</asp:ListView>
<asp:LinqDataSource ID="CodeSamplesDataSource" runat="server"
    ContextTypeName="CodemDatabaseDataContext" Select="new (Id, Language, Body)"
    TableName="CodeSamples" Where="MessageId == @MessageId">
    <WhereParameters>
        <asp:ControlParameter ControlID="messageView" Name="MessageId"
            PropertyName="SelectedValue" Type="Int64" />
    </WhereParameters>
</asp:LinqDataSource>
The output shows the <pre> boxes for each code snippet
and even displays the first line number (1) but not the content.

The HTML output looks like this:

<pre>
    <div><!-- Code highlighting 
              produced by Actipro CodeHighlighter (freeware)
                http://www.CodeHighlighter.com/ -->
        <span style="color: #008080;">1</span> 
    </div>
</pre>

<pre>
    <div><!-- Code highlighting 
              produced by Actipro CodeHighlighter (freeware)
                http://www.CodeHighlighter.com/ -->
        <span style="color: #008080;">1</span> 
    </div>
</pre>

<pre>
    <div><!-- Code highlighting 
              produced by Actipro CodeHighlighter (freeware)
                http://www.CodeHighlighter.com/ -->
        <span style="color: #008080;">1</span> 
    </div>
</pre>
If I hardcode the content it works fine.
So putting "Console.WriteLine("Hello");" instead of "<%# Eval("Body") %>"
works like a charm.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
It sounds like one of two things:
1) Your binding is wrong and doesn't send any content through, or
2) Our control initially runs with the default value (blank) before your binding is executed and the update you make doesn't execute our code again.

Since we know your language binding works, send that through instead and see if you get "C#" in the output or not. That should tell us.


Actipro Software Support

Posted 16 years ago by TimothyP
Avatar
The following code does output the content as requested:

<ItemTemplate>
<pre>
  <%# Eval("Body") %>  
</pre>
</ItemTemplate>
The same problem occurs when using Language
as the content for the SyntaxHighlighting control.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Could you put together a simple web site project that shows all this happening and email it over so that we can debug with it to make sure we correct the issue properly? Thanks!


Actipro Software Support

Posted 16 years ago by TimothyP
Avatar
Hi,
The problem is solved. This was my code:

<cc1:CodeHighlighter ID="codeHighlighter" runat="server" LanguageKey='<%# Eval("Language") %>'>
     <%# Eval("Body") %>
</cc1:CodeHighlighter>
The solution was to set the text using the property instead:

<cc1:CodeHighlighter ID="codeHighlighter" runat="server" LanguageKey='<%# Eval("Language") %>' Text='<%# Eval("Body") %>'/>
Setting the Text using the first method doesn't work for data bound values.
I don't know if this is a bug or not, but it works for me now.

Thank you for offering both great tools and great support :-)
The latest build of this product (v4.0.59) was released 13 years ago, which was after the last post in this thread.