asp.netvb.netrepeater

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


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?


Solution

  • It would help to see the broken version of your code, but I gather you're doing this:

    <p id='locationQuestions' title='This is some text <%# Container.DataItem %>' runat='server'></p>
    

    If that's the case, try it like this:

    <p id='locationQuestions' title='<%# "This is some text " & Container.DataItem %>' runat='server'></p>