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 / February 2008

Tip: Looking for answers? Try searching our database.

code behind not seeing a label

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jvcoach23 - 06 Feb 2008 19:27 GMT
I have the following code in the aspx

<asp:Label ID="lblRightWrong" runat="server" />

that is inside a datagrid, itemtemplate

the vb code behind

Me.lblRightWrong.text = "Correct"

but the lblRightWrong says that it does not exists... I've tried exiting
out of VS, tried to recreate it, nothin seems to work.. it always can't see
it.  i'm on VS 2005, sp1.  anyone have any ideas as to why it won't show
up... all my other referrences to the aspx page are working

thanks
shannon
sloan - 06 Feb 2008 19:41 GMT
That is designed behavior.

When its inside a datagrid (repeater, gridview) etc... you could N number of
these.

FindControl
http://www.google.com/search?source=ig&hl=en&rlz=&q=datagrid+FindControl

That'll get you on the right path.

>I have the following code in the aspx
>
[quoted text clipped - 14 lines]
> thanks
> shannon
jvcoach23 - 06 Feb 2008 19:50 GMT
ok.. that makes sense.. thanks

> That is designed behavior.
>
[quoted text clipped - 24 lines]
>> thanks
>> shannon
Mark Moeykens - 06 Feb 2008 21:14 GMT
This is correct, Shannon. Say your grid has 10 rows, then that label is
recreated 10 times. So if you try to set it, it doesn't know which one of the
10 you want to set.
So your page is working correctly, you just have to tweak it a bit to set
that label.

If you know ahead of time what the row index is that you want to change, you
can probably use code like this:

Dim rowIndex As Integer
rowIndex = 2
CType(GridView1.Rows(rowIndex).FindControl("lblRightWrong"), Label).Text =
"Correct"

Hope this gets you started in the right direction!

Mark Moeykens

> I have the following code in the aspx
>
[quoted text clipped - 13 lines]
> thanks
> shannon

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.