使用FindControl访问/分配数据列表中的控件时,提示:System.NullReferenceException:对象引用未设置为对象的实例. [英] When accesing/assigning control in Datalist using FindControl, Im getting: System.NullReferenceException: Object reference not set to an instance of an object.
本文介绍了使用FindControl访问/分配数据列表中的控件时,提示:System.NullReferenceException:对象引用未设置为对象的实例.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我这样做是这样的:
Im doing it like this:
<asp:DataList ID="DataList" runat="server" RepeatDirection="Horizontal"
Width="600px" CellPadding="5" CellSpacing="5">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" />
</ItemTemplate>
</asp:DataList>
后面的代码是:
图片img =(Image)DataList.FindControl("Image1");
img.ImgUrl = a.ImagePath
即使使用Label控件或其他控件,我也遇到相同的错误
任何想法吗?
and code behind is:
Image img = (Image)DataList.FindControl("Image1");
img.ImgUrl = a.ImagePath
Im getting same error even when using Label control or other control
Any idea ?
推荐答案
Label ramImage =(Label)e.Item.FindControl("lblno1");
Label ramImage=(Label)e.Item.FindControl("lblno1");
在后端使用此代码
标签lblno =(Label)e.Item.FindControl("lblno1");
找出您的控件.....:)
In backend use this code
Label lblno = (Label)e.Item.FindControl("lblno1");
to find out your controls.....:)
这篇关于使用FindControl访问/分配数据列表中的控件时,提示:System.NullReferenceException:对象引用未设置为对象的实例.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文