Reputation: 15
let's say I'm having 10 labels called "Label1", "Label2", "Label3".... "Label10". Is there a way to make a for loop which I could enter text for each Label its number?
I mean - Label1.Text will be "1". Label2.Text will be 2 , and so on till Label10.Text will be 10.
Thanks !
Upvotes: 0
Views: 374
Reputation: 9849
in your .cshtml
file you could do:
@{
for (int i = 0; i <= 10; i++)
{
var labelId = "Label" + i;
var labelText = "LabelText" + i;
<label id="@labelId">@labelText</label><br />
}
}
which results in:
Upvotes: 1