Click here to Skip to main content
12,952,159 members (55,871 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Im doing it like this:

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

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

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 11-Nov-12 8:41am
Updated 11-Nov-12 8:56am
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.
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.
Maho^^^ 23-Nov-12 11:15am
tnx it helped me.
Sergey Alexandrovich Kryukov 23-Nov-12 11:51am
My pleasure.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Label ramImage=(Label)e.Item.FindControl("lblno1");
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In backend use this code

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

to find out your controls.....:)
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 11 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100