WHy am I unable to add text along with <%# Container.DataItem %> in repeater in user control

Posted by Jamie Hartnoll on Stack Overflow See other posts from Stack Overflow or by Jamie Hartnoll
Published on 2011-11-26T17:31:57Z Indexed on 2011/11/26 17:51 UTC
Read the original article Hit count: 339

Filed under:
|
|

I have a User Control which is dynamically placed by CodeBehind as follows:

    Dim myControl As Control = CType(Page.LoadControl("~/Controls/mainMenu.ascx"), Control)
    If InStr(Request.ServerVariables("url"), "/Login.aspx") <= 0 Then
        mainMenu.Controls.Add(myControl)
    End If

As per an example from my previous question on here.

Within this Control is a repeater which calls a database to generate values.

My Repeater mark-up is as follows

<asp:Repeater runat="server" ID="locationRepeater" OnItemDataBound="getQuestionCount">                        
    <ItemTemplate>
       <p id='locationQuestions' title='<%# Container.DataItem %>' runat='server'></p>
    </ItemTemplate>
</asp:Repeater>

The example above works fine, but I want to be able to prepend text to <%# Container.DataItem %> in the title attribute of that <p> to print to the browser like this is some text DATA_ITEM_OUTPUT

When I try to do that though, it prints this is some text <%# Container.DataItem %> exactly like that, ie, turning <%# Container.DataItem %> into text, NOT the value from the repeater code.

It was working fine before I made it into a dynamically inserted control, so I am thinking I might have something being generated in the wrong order, but given that it works without any prepended text, I am stumped to fix it!

I'm new to .net and using vb.net, please could someone point me in the right direction?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about vb.net