The learning notes show multiple controls with the same ID "_ header". The findcontrol requires that the control has a unique ID.

Source: Internet
Author: User

Private void displayhotbooks ()
{
// Obtain the category information of all books
Ilist <Category> List = categorymanager. getallcategories ();
Int I = 0;
Foreach (Category item in List)
{
Accordionpane ap = new accordionpane ();
Label lbmenu = new label ();
Lbmenu. Text = item. Name;
AP. headercontainer. Controls. Add (lbmenu );
Accordion1.panes. Add (AP );
}
}

From the exception "_ Header", we can guess that it is related to the pane header. Therefore, we manually add a unique ID.

Private void displayhotbooks ()
{
// Obtain the category information of all books
Ilist <Category> List = categorymanager. getallcategories ();
Int I = 0;
Foreach (Category item in List)
{
Accordionpane ap = new accordionpane ();
Label lbmenu = new label ();
Lbmenu. Text = item. Name;
AP. headercontainer. Controls. Add (lbmenu );
AP. headercontainer. ID = "_ Header" + item. ID;
Accordion1.panes. Add (AP );
}
}

Then throw an exceptionFind multiple controls with the same ID "_ content. Findcontrol requires that the control have a unique ID. Haha, I almost forgot to add the Content ID manually in addition to the header and content. The final result is as follows:

Private void displayhotbooks ()
{
// Obtain the category information of all books
Ilist <Category> List = categorymanager. getallcategories ();
Int I = 0;
Foreach (Category item in List)
{
Accordionpane ap = new accordionpane ();
Label lbmenu = new label ();
Lbmenu. Text = item. Name;
AP. headercontainer. Controls. Add (lbmenu );
AP. headercontainer. ID = "_ Header" + item. ID;
AP. contentcontainer. ID = "_ content" + item. ID;
Accordion1.panes. Add (AP );
}
}

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.