简体   繁体   中英

i want to access 'ids' of asp.net server controls in for loop.so with single line i can set value to all controls

for(int i = 1; i < 5;i++)
{
    label[i].InnerText = info.books[0].title;
}

I want something like this to access id's of 5 server controls in loop. label1,label2,.....,label5. It is a code behind file.

If you really wanted you can use FindControl

for (int i = 1; i < 5; i++)
{
    Label lbl = Page.FindControl("Label" + i) as Label;
    lbl.Text = info.books[0].title;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM