Click here to Skip to main content
12,350,728 members (23,678 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET4
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>



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
Maho^^^1.2K
Edited 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.
Sergey Alexandrovich Kryukov 23-Nov-12 11:51am
   
My pleasure.
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Label ramImage=(Label)e.Item.FindControl("lblno1");
  Permalink  
Rate this: bad
 
good
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.....Smile | :)
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 11 Nov 2012
Copyright © CodeProject, 1999-2016
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