读书人

怎么在后台代码中设置APS.NET中imageb

发布时间: 2013-06-26 14:29:32 作者: rapoo

如何在后台代码中设置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啊,不能直接在模板上写名字的把,不然找不到的?

读书人网 >asp.net

热点推荐