TableRowCollection.GetEnumerator 方法的C#例子

None.gif 下面的示例展示如何使用 GetEnumerator 方法创建一个实现了 System.Collections.IEnumerator 的对象,该对象被循环访问以显示表中的项。
None.gif
None.gifview plaincopy to clipboardprint
?
None.gif
<% @ Page Language = " C# "  AutoEventWireup = " True "   %>    
None.gif  
None.gif
< HTML >    
None.gif 
< HEAD >    
None.gif    
None.gif    
< SCRIPT runat = " server " >   
None.gif   
ExpandedBlockStart.gifContractedBlock.gif       
void  Page_Load(Object sender, EventArgs e)  dot.gif {  
InBlock.gif            
InBlock.gif          
int numrows = 5;  
InBlock.gif          
int numcells = 6;  
InBlock.gif          
int counter = 1;  
InBlock.gif          ArrayList a_row 
= new ArrayList();  
InBlock.gif            
InBlock.gif          
// Create a table.  
ExpandedSubBlockStart.gifContractedSubBlock.gif
          for (int j=0; j<numrows; j++dot.gif{            
InBlock.gif             TableRow r 
= new TableRow();  
ExpandedSubBlockStart.gifContractedSubBlock.gif             
for (int i=0; i<numcells; i++dot.gif{  
InBlock.gif                TableCell c 
= new TableCell();  
InBlock.gif                c.Text
=counter.ToString();  
InBlock.gif                r.Cells.Add(c);  
InBlock.gif                counter
++;  
ExpandedSubBlockEnd.gif             }
  
InBlock.gif             Table1.Rows.Add(r);  
ExpandedSubBlockEnd.gif          }
  
InBlock.gif           
ExpandedBlockEnd.gif       }
  
None.gif   
ExpandedBlockStart.gifContractedBlock.gif    
void  Button_Click( object  sender, EventArgs e)  dot.gif {  
InBlock.gif   
InBlock.gif       
int row_counter = 0;  
InBlock.gif       TableRow current_row;  
InBlock.gif       TableCell current_cell;  
InBlock.gif   
InBlock.gif       
// Create an IEnumerator for the rows of a table.  
InBlock.gif
       IEnumerator myRowEnum = Table1.Rows.GetEnumerator();  
InBlock.gif   
InBlock.gif       Label1.Text 
= "The copied items from the table are: ";  
InBlock.gif   
InBlock.gif       
// Iterate through the IEnumerator and display its contents.  
ExpandedSubBlockStart.gifContractedSubBlock.gif
       while (myRowEnum.MoveNext()) dot.gif{  
InBlock.gif   
InBlock.gif          
// Create an IEnumerator for the cells of the row.  
InBlock.gif
          IEnumerator myCellEnum = Table1.Rows[row_counter].Cells.GetEnumerator();   
InBlock.gif            
InBlock.gif          
// Iterate through the IEnumerator and display its contents.  
ExpandedSubBlockStart.gifContractedSubBlock.gif
          while (myCellEnum.MoveNext()) dot.gif{  
InBlock.gif            
InBlock.gif             current_cell 
= (TableCell)myCellEnum.Current;  
InBlock.gif             Label1.Text 
= Label1.Text + " " + current_cell.Text;  
InBlock.gif   
ExpandedSubBlockEnd.gif          }
  
InBlock.gif         
InBlock.gif          row_counter
++;  
InBlock.gif   
ExpandedSubBlockEnd.gif       }
  
InBlock.gif        
ExpandedBlockEnd.gif    }
  
None.gif   
None.gif    
</ SCRIPT >    
None.gif    
None.gif    
None.gif    
None.gif    
None.gif    
None.gif    
< H3 > TableCellCollection Example </ H3 >    
None.gif    
< FORM runat = " server " >    
None.gif       
< ASP:TABLE id = Table1 runat = " server "   />    
None.gif       
< BR >< BR >    
None.gif       
< CENTER >    
None.gif          
< ASP:BUTTON id = Button1 onclick = Button_Click runat = " server "  Text = " Copy Table to Array "   />    
None.gif          
< BR >< BR >    
None.gif          
< ASP:LABEL id = Label1 runat = " server "   />    
None.gif    
None.gif       
</ CENTER >    
None.gif    
None.gif    
</ FORM >    
None.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值