日期:2014-05-18 浏览次数:20533 次
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 页代码贴一下
顺便把代码也改一下
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; }