ImageButton ishopital = (ImageButton)this.gvUrl.FindControl("IshopitaltUpdate");
        ishopital.ImageUrl = "../App_Themes/Web2ASPNET2/Images/delete.gif";请问兄弟些。为什么这样会提示“未将对象引用设置到对象的实例。”

解决方案 »

  1.   

    断点调试下撒,
    看看ishopital是否取到值 
      

  2.   

    ishopital 为null。
    (ImageButton)this.gvUrl.FindControl("IshopitaltUpdate");你这样写我不知道你怎么找得到?gridview里的吧?
      

  3.   

    (ImageButton)this.gvUrl.FindControl("IshopitaltUpdate");
    改为(ImageButton)this.gvUrl.rows["行号"].FindControl("IshopitaltUpdate");
      

  4.   

    GridViewRow row = gvUrl.Rows[index];
    ImageButton ishopital = (ImageButton)row.FindControl("IshopitaltUpdate");
      

  5.   

    for(int i=0;i<grv.Rors.Count;i++)
    {
    ishopital.ImageUrl = (ImageButton)this.gvUrl.Rows[i][yourCell].FindControl("IshopitaltUpdate");
    }
      

  6.   

    我觉得应该是你的gridview 这样拿不到,所以提示这个
      

  7.   

    同意,应该是FindControl时没有找到控件
    加个if(ishopital!=null)
    {
    ......
    }
      

  8.   

    ImageButton ishopital = (ImageButton)this.gvUrl.FindControl("IshopitaltUpdate");
    if(ishopital!=null)
      ishopital.ImageUrl = "../App_Themes/Web2ASPNET2/Images/delete.gif";ishopital 这个取不到吧
      

  9.   

    如果不是在RowCommand事件里面就用5楼的方法
      

  10.   

    this.gvUrl.FindControl("IshopitaltUpdate")
    错误原因: 这句 其实没有找到控件
      

  11.   

    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {ImageButton ishopital = e.Row.FindControl("IshopitaltUpdate") as ImageButton ;
    if(ishopital!=null)
    ishopital.ImageUrl = "~/App_Themes/Web2ASPNET2/Images/delete.gif";
         }
    }
      

  12.   

    xxx as yyy
    比(yyy)xxx 要安全
      

  13.   

    ImageButton ishopital = (ImageButton)this.gvUrl.FindControl("IshopitaltUpdate");
    应该没有取到这个ImageButton
    if(ishopital!=null)
    {
      //Write your code here
    }
      

  14.   

    很好很強大。rowdatabound是在给GridView绑定完数据后触发的 就是说数据绑定完了 但是需要做一些调整 就可以在这里做操作.試試吧
      

  15.   

    this.gvUrl.FindControl("IshopitaltUpdate")
    有问题注意如果 IshopitaltUpdate 是在什么容器里
      

  16.   

    先获取gridview的行,再从行里找控件
    另外,ishopital.ImageUrl = "../App_Themes/Web2ASPNET2/Images/delete.gif";
    别这么写,因为使用该image的页面如果不在虚拟目录根目录就会找不到图片,
    ishopital.ImageUrl = "~/App_Themes/Web2ASPNET2/Images/delete.gif";这样就是相对于虚拟目录绝对定位了,不会因为使用页面的位置的变化丢失