首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

帮帮小弟! gridview有关问题!1

2011-12-31 
帮帮小弟!! gridview问题!!1protected void gv_IsPopular_RowDataBound(object sender, GridViewRowEventA

帮帮小弟!! gridview问题!!1
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; 未将对象引用设置到对象的实例
  }

[解决办法]
没获取到。
[解决办法]
LinkButton up =e.Row.FindControl("linkbtn_Up") as LinkButton; 
--
看看是不是ID写错了
[解决办法]
不要写在RowDataBound事件里,建议在绑定完GridView之后添加以下代码:

C# code
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;  } }
[解决办法]
linkbtn_Up是在ItemTemplate还是EditItemTemplate中的,如果是在EditItemTemplate中,楼主这样得不到
[解决办法]
把代码帖完整
linkbtn_Up是在ItemTemplate还是EditItemTemplate中
[解决办法]
LinkButton up =e.Row.FindControl("linkbtn_Up") as LinkButton;
up肯定没有找到,最好在使用之前判断一下是否null然后再处理
否则就会"未将对象引用设置到对象的实例 "

[解决办法]
把ASPX 页代码贴一下

顺便把代码也改一下
C# code
            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;             } 

热点排行