Update text of many labels
Update text of many labels
(OP)
I have 10 labels in my mark up as follows
I am trying to set the text in a select in the code behind
Obviously this will not work as "lblHeadCOL" does not exist, but I cannot find the correct format. I think I have to use findcontrol. I have tried
Can anyone help me with the correct format please, or is there a better way.
Steve
CODE --> English
<asp:Label ID="lblHead1" runat="server"></asp:Label> <asp:Label ID="lblHead2" runat="server"></asp:Label> <asp:Label ID="lblHead3" runat="server"></asp:Label> <asp:Label ID="lblHead4" runat="server"></asp:Label> <asp:Label ID="lblHead5" runat="server"></asp:Label> <asp:Label ID="lblHead6" runat="server"></asp:Label> <asp:Label ID="lblHead7" runat="server"></asp:Label> <asp:Label ID="lblHead8" runat="server"></asp:Label> <asp:Label ID="lblHead9" runat="server"></asp:Label> <asp:Label ID="lblHead10" runat="server"></asp:Label>
CODE --> English
COL = 0 While MyMenu.Read Select Case MyMenu.GetInt32(1) Case 1 COL = COL + 1 lblHeadCOL.Text = "MyMenu.GetString(4)" Case 2 Case 3 Case 4 End Select End While
Obviously this will not work as "lblHeadCOL" does not exist, but I cannot find the correct format. I think I have to use findcontrol. I have tried
CODE --> English
Dim myLabel As Object = FindControl("lblHead1") myLabel.Text = "MyMenu.GetString(4)"
Steve
RE: Update text of many labels
You say you tried FindControl(), but you didn't say what the result was.
RE: Update text of many labels
CODE -->
CODE -->
What I am trying to do is read a table, and for every type 1 record (MyMenu.GetInt32(1) = 1) (There will be 10 of them) I want to change the .text values of lblHead1, lblHead2.......ldlHead10 with a field (MyMenu.GetString(4)) from each record read. Obviously, these values can change or I would just hard code the text values. These will be headings for data displayed below them. Hope this explains.
Steve
RE: Update text of many labels
Steve
RE: Update text of many labels
CODE
CODE
Dim myLabel As Label = (Page.FindControl("lblHead" + Col.ToString())) If myLabel is not nothing then myLabel.Text = MyMenu.GetString(4) End If
First make sure you are getting the label control,
Next, make sure you have a value from "MyMenu.GetString(4)"
RE: Update text of many labels
I now have this working. I used the following code.
CODE -->
Thanks for all your help jbenson001
RE: Update text of many labels