asp.netsessionlistviewdatabounddatabound-controls

Asp.Net Databound and Sessions Conditional Logic


Hello There I'm trying to set the visibility of button in list view item template based on the session object and databound property

<asp:Button ID="deleteCommentButton" runat="server" Text="Delete Comment"
            CssClass="redButton" 
            ToolTip="<%# Session[1].ToString() %>" 
            Visible="<%# Session[1].ToString() == Bind("fullname") ? true : false %>"
            style="float:right; margin-left:5px; margin-top:-25px;"
            onclick="deleteCommentButton_Click" />

But I'm getting errors . . Any suggestions?


Solution

  • Please try this

    <asp:Button ID="deleteCommentButton" runat="server" Text="Delete Comment"
            CssClass="redButton" 
            ToolTip='<%# HttpContext.Current.Session[1].ToString() %>' 
            Visible='<%# HttpContext.Current.Session[1].ToString() == Bind("fullname") ? true : false %>'
            style="float:right; margin-left:5px; margin-top:-25px;"
            onclick="deleteCommentButton_Click" />