is it 开发者_如何学Cpossible to access public page variables from ListView.EmptyDataTemplate ?
Can i do that and if can, how ?
thanks
Basically with:
<%= this.YourPagesPublicProperty%>
Example, my ASP.NET File:
<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>
And my .cs File:
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();
}
精彩评论