ASP.NET是否可以从ListView.EmptyDataTemplate访问公共页面变量?

时间:2010-06-13 14:11:28

标签: asp.net

是否可以从ListView.EmptyDataTemplate访问公共页面变量?

我可以这样做,如果可以,怎么做?

感谢

1 个答案:

答案 0 :(得分:0)

基本上用:

 <%= this.YourPagesPublicProperty%>

示例,我的ASP.NET文件:

<p>IntDicIsEmptyValue: <%= this.IntDicIsEmptyValue %></p>
<asp:ListView ID="ListView1" runat="server" >
    <LayoutTemplate>
        <ul runat="server" id="itemPlaceholder"></ul>    
    </LayoutTemplate>
    <ItemTemplate>
        <p><%# Eval("Key") %> / <%# Eval("Value") %></p>
    </ItemTemplate>
    <EmptyDataTemplate>
        <p>Status: <%= this.IntDicIsEmptyValue%></p>
    </EmptyDataTemplate>
</asp:ListView>

我的.cs文件:

public Dictionary<int,string> intdic;
public string IntDicIsEmptyValue { get; set; }


protected void Page_Load(object sender, EventArgs e)
{
    IntDicIsEmptyValue = "Is Empty";
    intdic = new Dictionary<int, string>();
    //Comment next two lines to see Emptydatatemplate with IsEmpty
    intdic.Add(3, "Three");
    intdic.Add(4, "Four");

    ListView1.DataSource = intdic;
    ListView1.DataBind();

}