Visibility of a link button on session variable asp c# repeater

1.1k Views Asked by At

Inside a repeater control I have a LinkButton, this LinkButton must only modify data that belongs to the same user that posted it, for this I need to evaluate a session variable and only show the LinkButton on the information that is owned by the signed user.

I've tried several variants of the following structure, yet I've had no success:

<asp:LinkButton ID="lnkocultar_post" runat="server" class="pull-right btn-box-tool" OnCommand="lnkocultar_post_Command" CommandArgument='<%# Eval("post_ID") %>' Visible='<%# bool.Parse(Session["Miembro_Id"] == Eval("Miembro_Id")) ? "true": "false"%>'>

<i class="fa fa-times">

</i>

</asp:LinkButton>
1

There are 1 best solutions below

1
On BEST ANSWER

To make the visibility of the control dependant on whether the id's match, you can just bind to a string comparison of the two.

<asp:LinkButton ID="lnkocultar_post" runat="server" class="pull-right btn-box-tool" OnCommand="lnkocultar_post_Command" CommandArgument='<%# Eval("post_ID") %>' Visible='<%# String.Equals(Session["Miembro_Id"], Eval("Miembro_Id"))%>'>
    <i class="fa fa-times"></i>
</asp:LinkButton>