获得codebehind公共串入的ListView的LayoutTemplate模板 [英] Get public string in codebehind into LayoutTemplate of ListView

查看:92
本文介绍了获得codebehind公共串入的ListView的LayoutTemplate模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET一个疑问(VB)

A doubt in ASP.NET(VB)

我在code-背后(ASPX.VB)公共变量

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

Public _orderCode As String = "Hello World"

在ASPX,我想在线访问。
那也是一个ListView的LayoutTemplate模板内

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>

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

我知道,如果它不是一个数据绑定控件内它会在页面内工作。
我需要的是使用内联code块来访问变量的方式。

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?

顺便说一句,我知道它在约束code-后面所有。
我要寻找一个具体的解决方案,如果有一个,一个确认,如果没有。

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.

推荐答案

这不能做,或者至少我对此表示怀疑。我的建议,使用文字控制或标签,并在code-背后分配文本。

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.

勾选此帖子
达科的回答是:
当页面正在被渲染,即执行内嵌code。在Page_ preRender事件之后和卸载事件之前。因此数据绑定后,您的在线code可能是一个'完了',它的工作。

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.

这篇关于获得codebehind公共串入的ListView的LayoutTemplate模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆