jmasterx
jmasterx

Reputation: 54113

Conditional HyperLink in GridView?

I have a gridview with a hyperlink:

<asp:GridView ID="gvEmployees" runat="server" AutoGenerateColumns="False"
 CssClass="table table-hover table-striped" GridLines="None" >
    <Columns>
        <asp:TemplateField HeaderText="Name" SortExpression="EmployeName">
            <ItemTemplate>
                <asp:HyperLink ID="HyperLink1" runat="server"
                    Text='<%# Bind("EmployeName") %>' ></asp:HyperLink>
            </ItemTemplate>

        </asp:TemplateField>
        <asp:TemplateField HeaderText="ID" SortExpression="EmployeID" Visible="False">
            <ItemTemplate>
                <asp:Label ID="lblID" runat="server" Text='<%# Bind("EmployeID") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

However, it should only appear as a hyperlink if the employeeID is that of the logged in employee.

I can do all that, but what I do not know is how to make the hyperlink look like a Label. It's easy to have it not link anywhere, but I do not know how to make it look like a label.

Thanks

Upvotes: 0

Views: 975

Answers (1)

Brian Mains
Brian Mains

Reputation: 50728

I believe if you set Enabled="false" it does. If it does not, then the only way to do that is put both a HyperLink and Label in the cell, and show the link when appropriate, and the label when appropriate, hiding the other one (which can be easily done in RowDataBound event).

Upvotes: 1

Related Questions