sara adly sara adly - 6 months ago 13
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
Item
object only in this way
<%# Item.IsDeleted %>

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


Update:-
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 ??

Answer

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" %>' />
</div>

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)
    {
        divContent.DataBind();
    }
}
Comments