2011-02-16 191 views
2

我有一個GridView。在那裏是2列,如圖像和狀態。在圖像列中,一些圖像將被禁用。爲此,光標手符號不應該來。如何改變這一點。這裏是我的代碼...光標手符號變化

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="List.ascx.cs" 
Inherits="List" %> 
<style type="text/css"> 
.noHand 
{ 
    cursor:default 
} 
</style> 
.......... 
......... 
    <asp:CommandField ButtonType="Image" ShowEditButton="True" HeaderText="Edit"  EditImageUrl="~/IMAGES/Edit.gif"> 
    <ItemStyle HorizontalAlign="Center" /> 
    </asp:CommandField> 

代碼隱藏

protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
     if (Status.Value == "True") 
     { 
      //Here Cursor Hand symbol should come 
     } 
     else 
     { 
      e.Row.Cells[9].CssClass = "nohand"; 
     } 
} 

回答

7

嘗試使用對細胞的CssClass屬性:

e.Row.Cells[cellIndex].CssClass = "nohand"; 

cellIndex是你的細胞在每行的從零開始的索引。

然後在您現有的樣式表中創建一個css類(或者創建一個新的樣式表並在應用程序中引用它),其名稱爲nohand,其中包含規則cursor:default;

2

你必須與具有光標屬性設置一個CSS類聯繫起來。無論你有代碼發出一個禁用的圖像命令,也放棄一些CSS來相應地設置你的光標。

http://www.w3schools.com/css/pr_class_cursor.asp

因此,創建一個CSS類是這樣的:

noHand {cursor:default} 

並確保它被設置爲禁用列。 @尼克的答案看起來就是這樣。

+0

在GridView上移動光標時,如果圖像被禁用,應該會出現默認光標,或者如果圖像被啓用,手形符號應該出現。 OnMouseOver,這些應該發生 – RobinHood 2011-02-16 21:47:30

+0

....這是我的CSS。如何在我的RowDataBound中使用這個 – RobinHood 2011-02-16 21:54:32