protected void gv_IsPopular_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {            LinkButton up =e.Row.FindControl("linkbtn_Up") as LinkButton;
            LinkButton down = e.Row.FindControl("linkbtn_down") as LinkButton;
            if (whetherLine == 1)
            {
                up.Enabled = false;
            }
            whetherLine++;
            if (whetherLine == a.Rows.Count)
            {
                down.Enabled = false;
            }
        }
    }
提示: if (whetherLine == 1)
            {
                up.Enabled = false;  未将对象引用设置到对象的实例
            }

解决方案 »

  1.   

    LinkButton up =e.Row.FindControl("linkbtn_Up") as LinkButton; 
    --
    看看是不是ID写错了
      

  2.   

    不要写在RowDataBound事件里,建议在绑定完GridView之后添加以下代码:foreach(GridViewItem gvi in this.gv_IsPopular.Items)
    {
    LinkButton up = (LinkButton)gvi.FindControl("linkbtn_Up"); 
    LinkButton down = (LinkButton)gvi.FindControl("linkbtn_down"); 
    if (whetherLine == 1) 

          up.Enabled = false; 
     } 
     whetherLine++; 
     if (whetherLine == gvi.Count) 
     { 
          down.Enabled = false; 
     } 
    }
      

  3.   

    linkbtn_Up是在ItemTemplate还是EditItemTemplate中的,如果是在EditItemTemplate中,楼主这样得不到
      

  4.   

    把代码帖完整
    linkbtn_Up是在ItemTemplate还是EditItemTemplate中
      

  5.   

    LinkButton up =e.Row.FindControl("linkbtn_Up") as LinkButton;
    up肯定没有找到,最好在使用之前判断一下是否null然后再处理
    否则就会"未将对象引用设置到对象的实例 "
      

  6.   

    inkbtn_Up是在ItemTemplat中的 
      

  7.   

    把ASPX 页代码贴一下顺便把代码也改一下            LinkButton up =e.Row.FindControl("linkbtn_Up") as LinkButton; 
                LinkButton down = e.Row.FindControl("linkbtn_down") as LinkButton; 
                if (whetherLine == 1) 
                { 
                    if(up!=null)
                      up.Enabled = false; 
                } 
                whetherLine++; 
                if (whetherLine == a.Rows.Count) 
                { 
                    if(down!=null)
                        down.Enabled = false; 
                }