asp.netvb.netdatagrid.net-2.0request.servervariables

Show/Hide hyperlink in datagrid based on ServerVariable


I have the following in a datagrid using .NET 2:

<asp:HyperLink runat="server" NavigateUrl='<%# "edit.aspx?f=" & DataBinder.Eval(Container.DataItem, "forum_id") & "&t=" & DataBinder.Eval(Container.DataItem, "thread_id") & "&p=" & DataBinder.Eval(Container.DataItem, "post_id") %>' Text="Edit" ID="Hyperlink1"></asp:HyperLink>

At the moment, this link appears in all posts (or datagrid rows) in a simplistic forum I coded years ago.

I can detect the user using the forum with the following code:

Request.ServerVariables("LOGON_USER")

How do I show/hide the hyperlink on each post based on the servervariable?

So if I have 10 posts in a particular page, where 3 of those posts are by user x, how do I only show that hyperlink when user x is viewing that page, only on the posts which user x created?


Solution

  • try adding visible attribute with the following code :

    <asp:HyperLink visible='<%# Request.ServerVariables("LOGON_USER") == "x" %>' runat="server" NavigateUrl='<%# "edit.aspx?f=" & DataBinder.Eval(Container.DataItem, "forum_id") & "&t=" & DataBinder.Eval(Container.DataItem, "thread_id") & "&p=" & DataBinder.Eval(Container.DataItem, "post_id") %>' Text="Edit" ID="Hyperlink1"></asp:HyperLink>