开发者

ASP.Net C# ListView inline conditions

In have a list of objects bound to a ListView that is used to make a nice list of these items. In this ListView I have 1 colu开发者_Go百科mn that shoud have a specific condition to display a specific string. Is this possible using inline code or should I get a workaround using the codebehind?

This is what I would like to do:

<% if (((Recipe)Container.DataItem).Status == RecipesModel.REJECTED) { %>
Something goes here
<% } %>

But this returns this exception:

The name 'Container' does not exist in the current context

EDIT: this code is used inside <ItemTemplate>

EDIT 2: I found myself using the following code for this problem:

<asp:PlaceHolder id="place_public" runat="server" Visible='<%# ((Recipe)Container.DataItem).Status == RecipesModel.VALIDATED %>'>
Something here
</asp:PlaceHolder>


you cannot use Container.DataItem outside of data binding context

try something like

<%# Container.DataItem ... %>

eg:

<%# ((String)Container.DataItem).ToUpper() == "test" ? "IsTest" : "NotTest" %>


You may want to import the namespace of the container class in your .aspx page. for example:

<%@ Import Namespace="Container Class namespace" %> 


It looks like you are trying to use the Container object outside of its scope. Can you post the rest of the code so we can see what is happening on the page?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜