【问题标题】:Change cursor of a imagebutton set from cs page?从cs页面更改图像按钮集的光标?
【发布时间】:2013-09-11 04:15:46
【问题描述】:

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

【问题讨论】:

    标签: c# javascript html asp.net gridview


    【解决方案1】:

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

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

    3.css

    image id/ image class
    {
    cursor:pointer;
    }
    

    【讨论】:

      【解决方案2】:

      试试下面的代码:

      "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;
      }
      

      【讨论】:

      • Twick 仅通过一行完成...感谢您的帮助
      【解决方案3】:

      单行代码为我带来了魔力

      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);
      

      【讨论】:

        猜你喜欢
        • 2011-11-07
        • 1970-01-01
        • 1970-01-01
        • 2012-03-16
        • 1970-01-01
        • 1970-01-01
        • 2012-05-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多