![]() |
Hiding a hyperlink in a non-databound datagrid column
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? |
Re: Hiding a hyperlink in a non-databound datagrid column
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 "BobRoyAce" <bob@omegasoftwareinc.com> wrote in message news:R7idnYpErdFZxnLcRVn-og@comcast.com... > 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? > > |
Re: Hiding a hyperlink in a non-databound datagrid column
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? |
| All times are GMT. The time now is 09:46 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.