views:

328

answers:

1

Hi guys,

A doubt in ASP.NET(VB)

I have a public variable in code-behind(ASPX.VB)

Public _orderCode As String = "Hello World"

At ASPX, I would like to access it inline. That too inside the LayoutTemplate of a ListView

<asp:ListView runat="server" ID="listView_OrderReplies" 
                DataKeyNames="ProductID"
                DataSourceID="sdsProducts">
    <LayoutTemplate>
        <h1>Order Replies for Order Code  = <%# _orderCode %></h1>
        <asp:PlaceHolder ID="itemPlaceholder" runat="server" ></asp:PlaceHolder>
    </LayoutTemplate>
    <ItemTemplate>
        <b>Name</b>:  <%#Eval("ProductName")%><br />
        <b>Stock</b>:  <%#Eval("UnitsInStock")%><br />
        <b>Price</b>:  <%#Eval("UnitPrice")%> <br />
    </ItemTemplate>
</asp:ListView>

That is, I want this inline binding to succeed

<h1>Order Replies for Order Code  = <%# _orderCode %></h1>

or

<h1>Order Replies for Order Code  = <%= _orderCode %></h1>

I know it will work inside the page if its not inside a databound control. What I need is a way to access the variable using inline code blocks.

Is it possible? Can anybody point me in the right direction?

BTW, I know to bind it in code-behind and all. I am looking for a specific solution if there is one and a confirmation if there isn't.

+1  A: 

It cannot be done or at least I doubt it. My advise, use a literal control or label and assign the text at code-behind.

Check this post . Darko's answer was: Inline code is executed when the page is being rendered ie. after the Page_PreRender event and before the Unload event. Hence after databinding, your inline code is probably a 'goner' for it to work.

o.k.w