Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Object reference not set to an instance of an object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ben - 26 Jun 2007 08:51 GMT
Hi,

I want to access in code-behind a label within the ItemTemplate of a
Formview.

<asp:FormView ID="FormView1" runat="server" DataKeyNames="id"
DataSourceID="SqlDataSource1" >
<ItemTemplate>
<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name")
%>'></asp:Label>

code-behind:
Dim name As String = CType(FormView1.FindControl("nameLabel"), Label).Text

I get the error: "Object reference not set to an instance of an object"

Could somebody tell me what's wrong in my code?
Thanks
Ben
Eliyahu Goldin - 26 Jun 2007 09:06 GMT
Try

FormView1.Row.FindControl(...)

Signature

Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

> Hi,
>
[quoted text clipped - 15 lines]
> Thanks
> Ben
Masudur - 26 Jun 2007 10:05 GMT
On Jun 26, 2:06 pm, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.org> wrote:
> Try
>
[quoted text clipped - 24 lines]
> > Thanks
> > Ben

hi
,

if (FormView1.DefaultMode == FormViewMode.ReadOnly)
{
  Label lbl =  (Label)   FormView1.FindControl("nameLabel");
}

thanks
Masudur
Peter Bromberg [C# MVP] - 26 Jun 2007 14:54 GMT
As a general rule, it's a good idea to break up the statements in a single
line multi-expression code line into their own lines of code to facilitate
setting breakpoints and being able to examine values.  The way you have it
now, it would be extremely difficult to tell what is going on.

-- Peter
Site:  http://www.eggheadcafe.com
UnBlog:  http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA):    http://www.blogmetafinder.com

> Hi,
>
[quoted text clipped - 15 lines]
> Thanks
> Ben

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.