首页 > 解决方案 > 为asp.net gridview中的各个行设置“手指”光标

问题描述

我在 asp.net gridview 的模板字段中使用了 asp.net 复选框。通过在 .css 文件中包含以下内容,我将这些复选框设置为在将鼠标悬停在复选框上时使用“手指”光标:

input[type="checkbox"] {
    cursor: pointer;
}

gridview 中的某些复选框将被禁用。这是使用 gridview 的 RowDataBound 事件在代码中设置的:

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        [various code to set up a chkbox variable]
        if ( [various conditions] )
        {
            chkbox.Enabled = false;
        }
        else
        {
            chkbox.Enabled = true;
        }
    }
}

以上所有工作。我还想做的是在将鼠标悬停在禁用的复选框上时停止光标变为指向手指。我尝试设置 chkbox 的 ID 和 CssClass 属性,并包括合适的附加 CSS 语句。例如

            chkbox.Enabled = false;                
            chkbox.CssClass = "nohand";

在 .css 文件中:

.nohand {
    cursor: default;
}

但是这些并没有压制手指。任何人都可以提出一种方法来实现这一目标吗?提前感谢您的帮助。我是新来的 - 如果之前有人问过这个问题但我没有找到它,我很抱歉。

标签: c#cssasp.net

解决方案


关于什么:

input[type="checkbox"] {
    cursor: pointer;
}
input[type="checkbox"]:disabled {
    cursor: default;
}

推荐阅读