我想让那个图片当鼠标移上去的时候换成另外一张,怎么做啊,谢谢大家指点,我是新手

解决方案 »

  1.   

    this.Image1.Attributes.Add("onmouseover","xx(this)");
    <script>
    function xx(varImage)
    {
     varImage.src = " ../images/b2.jpg";
    }
    </script>
      

  2.   

    在datagrid的ItemDataBound事件中给图片绑定事件
      

  3.   

    this.Image1.Attributes.Add("onmouseover","xx(this)");
    <script>
    function xx(varImage)
    {
     varImage.src = " ../b2.jpg";
    }
    </script>
    这样就可以了啊
      

  4.   

    建议在datagrid的ItemCreated事件中添加JS事件
    (Image) img = (Image)e.Item.findcontrol("Image1");
    img.ImageUrl = 1.gif;
    img.Attributes.add("onmouseover", "this.src=2.gif");
    img.attributes.add("onmouseout", "this.src=1.gif");
      

  5.   

    this.Image1.Attributes.Add("onmouseover","xx(this)");这句放在cs文件的pageload事件里面不可以吗?我运行了怎么报错了:异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 25:  private void Page_Load(object sender, System.EventArgs e)
    行 26:  {
    行 27:  this.Image1.Attributes.Add("onmouseover","changepic(this.Image1)");
    行 28: // string myConnection=System.Configuration.ConfigurationSettings.AppSettings["connString"];
     
      

  6.   

    用上面的方法的话,你要用FindControl先把图片找出来
    或者你可以直接在HTML代码的模版列中,给<IMG>对象加上Javascript也可以的
      

  7.   

    它说img在类或者命名空间中不存在
      

  8.   

    (Image) img = (Image)e.Item.findcontrol("Image1");
    img.ImageUrl = 1.gif;
    img.Attributes.add("onmouseover", "this.src=2.gif");
    img.attributes.add("onmouseout", "this.src=1.gif");
      

  9.   

    为什么我在itemcreat事件里面用findcontrol会找不到image1这个控件
      

  10.   

    简单:
    private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    TableCell cell = e.Item.Cells[e.Item.Cells.Count-1];
    Image img= (Image)(cell.Controls[0]);
    img.Attributes.Add("onclick", "click()");
    }
    }
    e.Item.Cells[e.Item.Cells.Count-1]:
    -1代表最后表格最后一列;
    -2表示倒数第二列
    或e.Item.Cells[列数]
      

  11.   

    用<img  onmouseover="this.src=图片地址" onmouseover="this.src=另一图片地址">多好啊,能不能服务器控件就不用服务器控件。
      

  12.   

    不可以用html标签代替的,因为要写事件的
      

  13.   

    控件放在datagrid里面的话,用findcontrol找不到这个控件,为什么啊,因为datagrid里面有多条记录的原因???
      

  14.   

    Image img= (Image)(cell.Controls[0]);
    这句报错,说转换无效