日期:2014-05-17  浏览次数:20566 次

如何在后台代码中设置APS.NET中imagebutton的背景图片?
本帖最后由 fengyuzhengfan 于 2013-06-06 14:19:00 编辑
protected void DataList2_ItemDataBound(object sender,DataListItemEventArgs e)
    {
 ((ImageButton)e.Item.FindControl("lkbAtten")).ImageUrl="~/image/atten/关注.png";

可是这一句
 ((ImageButton)e.Item.FindControl("lkbAtten")).ImageUrl="~/image/atten/关注.png";
出现了“未将对象引用设置到对象的实例”问题请各位大哥告诉告诉我怎么解决?
ImageButton 背景图片 asp.net控件

------解决方案--------------------
我觉得很有可能是((ImageButton)e.Item.FindControl("lkbAtten"))这句没找到对象。
ImageButton tempButton = (ImageButton)e.Item.FindControl("lkbAtten");
tempButton.ImageUrl = "~/image/atten/关注.png";
改成这样,设断点看看tempButton是什么东西,是否为空。如果为空,就是找不到啦。
顺便问下DataList2下,你设置了几个lkbAtten的ImageButton啊,不能直接在模板上写名字的把,不然找不到的?