从 cs 页面更改图像按钮集的光标

Change cursor of a imagebutton set from cs page?

本文关键字:按钮 光标 图像 cs      更新时间:2023-09-26

我正在绑定行数据的网格视图上设置图像..在同一行中,图像将显示在某些它没有.所以我根据业务逻辑从CS页面添加它。我只想将光标显示为手?如何更改图像图标的样式。

if (e.Row.Cells[16].Text == "0")
                        {
                            e.Row.Cells[16].Text = string.Empty;
                        }
                        else
                        {
                            ImageButton img1 = new ImageButton();
                            img1.ImageUrl = "images/ablue.GIF";
                            img1.Height = 14;
                            img1.Width = 20;
                            img1.ToolTip = "Image Available";
                            img1.Attributes.Add("OnClick", "javascript:return SetId('" + e.Row.Cells[2].Text.ToString() + "');");
                            e.Row.Cells[16].Controls.Add(img1);
                        }

这里的图像是嚎叫,但不在手光标中。

1.为图像提供类名称或 ID。

2.然后在css中使用该名称或ID

3.css

image id/ image class
{
cursor:pointer;
}

尝试以下代码:

"imageButtonClass";**

 if (e.Row.Cells[16].Text == "0")
      {
           e.Row.Cells[16].Text = string.Empty;
      }
      else
      {
           ImageButton img1 = new ImageButton();
           img1.ImageUrl = "images/ablue.GIF";
           img1.Height = 14;
           img1.Width = 20;
           img1.ToolTip = "Image Available";
           img1.cssClass = "imageButtonClass";
           img1.Attributes.Add("OnClick", "javascript:return SetId('" + e.Row.Cells[2].Text.ToString() + "');");
           e.Row.Cells[16].Controls.Add(img1);
      }

在外部 CSS 或样式中:

img1.cssClass

.imageButtonClass
{
    cursor:pointer;
}

单行代码为我创造了魔力

img1.Style.Add("OnPreRender", "text-align:center;cursor:pointer;");

 ImageButton img1 = new ImageButton();
                            img1.ImageUrl = "images/ablue.GIF";
                            //Changed on Sept-11 to show the Cursor as Hand of Imagebutton
                            img1.Style.Add("OnPreRender", "text-align:center;cursor:pointer;");
                            img1.Height = 14;
                            img1.Width = 20;
                            img1.ToolTip = "Image Available";
                            img1.Attributes.Add("OnClick", "javascript:return SetId('" + e.Row.Cells[2].Text.ToString() + "');");
                            e.Row.Cells[16].Controls.Add(img1);