How to change the text of the multiple asp:label using for loop in C# ASP.NET
- by Minelava
I want to change the asp label multiple times.
Here is the asp.net code
<asp:Label ID="lbl_Text1" runat="server" Text="">
<asp:Label ID="lbl_Text2" runat="server" Text="">
<asp:Label ID="lbl_Text3" runat="server" Text="">
<asp:Label ID="lbl_Text4" runat="server" Text="">
Instead of using this:
C# Code
lbl_Text1.Text = "hello";
lbl_Text2.Text = "hello";
lbl_Text3.Text = "hello";
lbl_Text4.Text = "hello";
I tried to use for loop
for (int i = 1; i <= 4; i++)
{
lbl_Text[i].Text = "hello";
}
And I get this error.....
cannot apply indexing with [] to an expression of type 'system.web.ui.webcontrols.label'
Is there anyone can help me on that?