Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im doing it like this:

XML
<asp:DataList ID="DataList" runat="server" RepeatDirection="Horizontal"
                                        Width="600px" CellPadding="5" CellSpacing="5">


                                        <ItemTemplate>
                                            <asp:Image ID="Image1" runat="server" />
                                        </ItemTemplate>
                                    </asp:DataList>




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 ?
Posted
Updated 11-Nov-12 8:56am
v2
Comments
Himanshu Yadav 11-Nov-12 22:51pm    
Are you able to see path in grid.Your column is not filling with value thats why is giving exception when you trying to read the value.
Sergey Alexandrovich Kryukov 11-Nov-12 23:38pm    
In what line the exception is thrown? It that "img.ImgUrl = a.ImagePath"?
Then the problem is that FindControl returns null, and you are trying to dereference the result.
--SA
Maho^^^ 12-Nov-12 15:20pm    
yes, exception thrown exactly at "img.ImgUrl = a.ImagePath"
Sergey Alexandrovich Kryukov 12-Nov-12 16:26pm    
"img" or "a" is null. Check up under the debugger, that's it.
--SA
Maho^^^ 23-Nov-12 11:15am    
tnx it helped me.

Label ramImage=(Label)e.Item.FindControl("lblno1");
 
Share this answer
 
In backend use this code

Label lblno = (Label)e.Item.FindControl("lblno1");

to find out your controls.....:)
 
Share this answer
 
Comments
Maho^^^ 12-Nov-12 15:33pm    
yes I have tried that ... but I think e.Item or something like that is used for handling evants, I just want to access <asp:Image control and to add ImageUrl to it which is just a string value

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900