code behind not seeing a label

  • Thread starter Thread starter jvcoach23
  • Start date Start date
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
 
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
 
Back
Top