Nadlir
Nadlir

Reputation: 15

Inputing text into labels with for loop

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

Answers (1)

Daniel
Daniel

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:

enter image description here

Upvotes: 1

Related Questions