sara adly sara adly - 9 months ago 39
Javascript Question

if condtion inside div tag

I need to do this condition inside the div to display the first word if isdeleted== true

<div style="display:inline-block;float:right;padding-right:10px;margin-right:10px;">
<%# Item.IsDeleted ? 'not active':'active' %> </div>

page can recognize
object only in this way
<%# Item.IsDeleted %>

and can't recognize it in this way
<% if(Item.IsDeleted)%>

what IF i add

<asp:HiddenField ID="hiddenisdeleted" Value=" <%# Item.IsDeleted %>" runat="server" Visible="false"/>

how can I check value of the hidden field inside the Div tag ??


You can use a Literal control:

<div style="display: inline-block; float: right; padding-right: 10px; margin-right: 10px;">
    <asp:Literal ID="divContent" runat="server" Text='<%# Item.IsDeleted ? "not active": "active" %>' />

I assume that Item is defined and accessible in code-behind, and that it has an IsDeleted property.

If the div is not inside a databound control, you must call divContent.DataBind() to make sure that the databinding expression is evaluated:

protected void Page_Load(object sender, EventArgs e)
    if (!Page.IsPostBack)