0

我在行数据绑定的网格视图上设置图像..在同一行中,图像将显示在某些它不显示的位置。所以我根据业务逻辑从 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);
                        }

这里的图像是howing,但不是在手游标。

4

3 回答 3

0

试试下面的代码:

“图像按钮类”;**

 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.css类

.imageButtonClass
{
    cursor:pointer;
}
于 2013-09-11T04:28:07.360 回答
0

1.为您的图像提供类名或 id。

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

3.css

image id/ image class
{
cursor:pointer;
}
于 2013-09-11T04:28:27.807 回答
0

单行代码为我创造了魔力

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);
于 2013-09-18T08:46:42.880 回答