Hiding a hyperlink in a non-databound datagrid column

B

BobRoyAce

I am brand new to ASP.NET and am now required to take over maintenance of a
..NET/C# web application. On one of the pages I'm working on there is a
DataGrid which has multiple columns. One of the columns is not databound and
instead has up to three hyperlinks in it (Edit, Award, and Cancel). A couple
of the hyperlinks should not be shown in certain cases. Now, mind you, I
don't know if it's being done in the way that's best to do it. It looks like
there is a "panel" being created to contain the hyperlinks that may not be
visible. I don't know why though (i.e. why not just set hyperlink's Visible
property and be done with it without a panel?). That being said, I want to
change the page so that one of the hyperlinks does not show (i.e. Visible =
False) based on a certain value for a session cookie. It's the Award link in
the code shown below from the .aspx file in question.

--- CODE BEGINS ---

<asp:TemplateColumn HeaderText="Actions">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:HyperLink id="hlEdit" runat="server" NavigateUrl='<%#
"Edit.aspx?id=" + DataBinder.Eval(Container, "DataItem.PersonID") %>'
CssClass="link-text"> <!--onMouseOver='<%# "javascript:toolTip(\"" +
DataBinder.Eval(Container, "DataItem.PersonToolTip") + "\");" %>'
onMouseOut="javascript:toolTip();">-->
Edit
</asp:HyperLink>
<asp:panel ID="Panel1" Runat="server" Visible='<%#
Convert.ToBoolean(Convert.ToInt32(Request.Cookies["core"]["sl"]) <= 9)%>'>
<asp:HyperLink id=hlBids runat="server" Visible='<%#
Convert.ToBoolean(Convert.ToInt32(Request.Cookies["core"]["sl"]) <= 9)%>'
NavigateUrl='<%# "Award.aspx?id=" + DataBinder.Eval(Container,
"DataItem.PersonID") %>' CssClass="link-text">
Award
</asp:HyperLink>
</asp:panel>
<asp:panel ID="panAction" Runat="server" Visible='<%#
Convert.ToBoolean(DataBinder.Eval(Container,
"DataItem.PersonStatusCancel"))%>'>
<asp:HyperLink id="hlCancel" runat="server" NavigateUrl='<%#
"Cancel.aspx?id=" + DataBinder.Eval(Container, "DataItem.PersonID") +
"&op=cancel" %>' Visible='<%# Convert.ToBoolean(DataBinder.Eval(Container,
"DataItem.PersonStatusCancel"))%>' CssClass="link-text" >
Cancel
</asp:HyperLink>
</asp:panel>
</ItemTemplate>
</asp:TemplateColumn>

--- CODE ENDS ---

Now, the value of the cookie, when I bring up this page, is 1 which
satisfies the condition. I guess my question is two-part: 1) What is best
way to accomplish something like this? 2) If this is best way to do it, then
what's wrong?
 
E

Eliyahu Goldin

On of the reasons for not using Visible is that hidden controls don't get
rendered to client. If there is something to do with hidden controls on
client side, you can't use Visible.

Eliyahu
 
B

BobRoyAce

huh? I'm not sure what you're saying here. Links are currently being
"hidden" right now successfully by interrogating data behind the grid (e.g.
the Cancel link) and setting Visible = False. What doesn't seem to be
working, and what I need help with, is making things invisible based on a
session cookie's value. Is that doable?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top