Asp. NET control groups (Lable1, Label2, Label3.....labeln) are assigned

Source: Internet
Author: User

Requirements: A set of identical controls, Lable1, Label2, Label3.....labeln, which need to be assigned values.

1. In general, use FindControl to find the name of the control, plus the sequence number. Below, my control names are: Lbl1,lbl2,lbl3,lbl4. Here, directly with the int type I, there is no problem.

 for (int14; i++) {     = (Label)this. FindControl ("lbl" + i);      = i.tostring ();}

2. However, when the label group is in a container, this will cause an error. you need to find the container first, and then locate the label. as follows. Because the master page is used, the control group is actually in ContentPlaceHolder1, so first FindControl to ContentPlaceHolder1, FindControl to the Label control group.

 for (int14; i++) {        = (Label)this. Page.Master.FindControl ("ContentPlaceHolder1"). FindControl ("lbl" + i);         = i.tostring ();}

Asp. NET control groups (Lable1, Label2, Label3.....labeln) are assigned

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.