ListView bug解决方法

本文将介绍如何在复杂的控件集合中使用递归方法精确查找特定控件,包括文本框和属性设置,同时演示了如何利用客户端ID进行动态属性绑定。

  1. public static Control FindControl(string controlId, ControlCollection controls)  
  2.         {  
  3.             foreach (Control control in controls)  
  4.             {  
  5.                 if (control.ID == controlId)  
  6.                     return control;  
  7.                 if (control.HasControls())  
  8.                 {  
  9.                     Control nestedControl = FindControl(controlId, control.Controls);  
  10.                     if (nestedControl != null)  
  11.                         return nestedControl;  
  12.                 }  
  13.             }  
  14.             return null;  
  15.         }  
  16.         protected void ListView1_Load1(object sender, EventArgs e)  
  17.         {  
  18.             TextBox InDateTextBox = FindControl("InDateTextBox", ListView1.Controls) as TextBox;  
  19.             TextBox PriceTextBox = FindControl("PriceTextBox", ListView1.Controls) as TextBox;  
  20.             TextBox CountTextBox = FindControl("CountTextBox", ListView1.Controls) as TextBox;  
  21.             TextBox AmountTextBox = FindControl("AmountTextBox", ListView1.Controls) as TextBox;  
  22.             if (InDateTextBox != null && PriceTextBox != null && CountTextBox != null && AmountTextBox != null)  
  23.             {  
  24.                 InDateTextBox.Text = DateTime.Now.ToShortDateString();  
  25.                 AmountTextBox.Attributes["onfocus"] = "calcAmount('" + AmountTextBox.ClientID + "','"  
  26.                     + PriceTextBox.ClientID +  
  27.                     "','" + CountTextBox.ClientID + "')";  
  28.             }  
  29.         }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值