Example C # Of the tablerowcollection. getenumerator Method

Source: Internet
Author: User
The following example shows how to use the getenumerator method to create an object that implements system. Collections. ienumerator. This object is cyclically accessed to display items in the table.

View plaincopy to clipboardprint?
<% @ Page Language = "C #" autoeventwireup = "true" %>

<HTML>
<Head>

<SCRIPT runat = "server">

Void page_load (Object sender, eventargs e ){

Int numrows = 5;
Int numcells = 6;
Int counter = 1;
Arraylist a_row = new arraylist ();

// Create a table.
For (Int J = 0; j <numrows; j ++ ){
Tablerow r = new tablerow ();
For (INT I = 0; I <numcells; I ++ ){
Tablecell c = new tablecell ();
C. Text = counter. tostring ();
R. cells. Add (C );
Counter ++;
}
Table1.rows. Add (R );
}

}

Void button_click (Object sender, eventargs e ){

Int row_counter = 0;
Tablerow current_row;
Tablecell current_cell;

// Create an ienumerator for the rows of a table.
Ienumerator myrowenum = table1.rows. getenumerator ();

Label1.text = "the copied items from the table are :";

// Iterate through the ienumerator and display its contents.
While (myrowenum. movenext ()){

// Create an ienumerator for the cells of the row.
Ienumerator mycellenum = table1.rows [row_counter]. cells. getenumerator ();

// Iterate through the ienumerator and display its contents.
While (mycellenum. movenext ()){

Current_cell = (tablecell) mycellenum. Current;
Label1.text = label1.text + "" + current_cell.text;

}

Row_counter ++;

}

}

</SCRIPT>





<H3> tablecellcollection example <Form runat = "server">
<Asp: Table id = Table1 runat = "server"/>
<Br>
<Center>
<Asp: button id = button1 onclick = button_click runat = "server" text = "Copy table to array"/>
<Br>
<Asp: Label id = label1 runat = "server"/>

</Center>

</Form>

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.