code behind not seeing a label

J

jvcoach23

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
 
M

Mark Moeykens

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top