How to obtain child controls in repeater and listview

Source: Internet
Author: User

In the CS post-file of ASP. NET, you cannot directly use the control ID to operate the child control in the data binding control. You must use findcontrol to locate the control.

// Find the child control protected void repeaterincluitemdatabound (Object sender, repeateritemeventargs E) in repeater {// E. item. itemtype is the type of the current row if (E. item. itemtype = listitemtype. item | E. item. itemtype = listitemtype. alternatingitem) {// find the Textbox Control whose ID is btndelete, E. item indicates the currently bound textbox txtname = (textbox) E. item. findcontrol ("btndelete"); txtname. TEXT = "I am the child control found in repeater"; }}// find the child control protected void listviewincluitemdatabound (Object sender, listviewitemeventargs E) in listview) {// here is slightly different from repeater if (E. item. itemtype = listviewitemtype. dataitem) {textbox txtname = (textbox) E. item. findcontrol ("btndelete"); txtname. TEXT = "I am a child control found in listview ";}}

After the datatable is bound to the repeater, obtain a field value of the current data row:

Datarow ROW = (datarow) (datarowview) E. Item. dataitem). row;

String parentid = row ["parentid"]. tostring (); // obtain the parentid value of the current data row

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.