2013-02-06 23 views
0

我有一個超鏈接的GridView:GridView中的條件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> 

然而,它應該只顯示爲超鏈接,如果僱員是登錄的員工。

我可以做所有這些,但我不知道的是如何使超鏈接看起來像一個標籤。很容易讓它不能鏈接到任何地方,但我不知道如何使它看起來像一個標籤。

謝謝

回答

1

我相信,如果你設置Enabled =「false」它確實。如果沒有,那麼唯一的方法是在單元格中放置HyperLink和Label,並在合適的時候顯示鏈接,並在適當的時候顯示標籤,隱藏另一個(可以在RowDataBound事件中輕鬆完成) 。