2011-02-16 152 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