引用动态添加的控件
我在form_load里动态添加一控件:
if(tableName == "CostInvoice ")
{
ArrayList list = new ArrayList();
list.Add (new DictionaryEntry ( "1 ", "日期 "));
list.Add (new DictionaryEntry ( "2 ", "货号 "));
list.Add (new DictionaryEntry ( "3 ", "品名 "));
list.Add (new DictionaryEntry ( "4 ", "规格 "));
list.Add (new DictionaryEntry ( "5 ", "单位 "));
list.Add (new DictionaryEntry ( "6 ", "总成本 "));
list.Add (new DictionaryEntry ( "7 ", "零售价 "));
list.Add (new DictionaryEntry ( "8 ", "等级 "));
list.Add (new DictionaryEntry ( "9 ", "审核 "));
this.comboBox1.DataSource = list;
this.comboBox1.DisplayMember = "Value ";
this.comboBox1.ValueMember = "Key ";
if(colsIndex == "Date ")
{
this.comboBox1.SelectedIndex = 0;
System.Windows.Forms.DateTimePicker DateTimePicker1 = new System.Windows.Forms.DateTimePicker();
DateTimePicker1.Parent = this.groupBox1;
DateTimePicker1.Name = "DateTimePicker1 ";
DateTimePicker1.Location = new Point(88,48);
DateTimePicker1.Size = new Size(121,20);
this.Controls.Add(DateTimePicker1);
DateTimePicker1.BringToFront();
DateTimePicker1.Value = DateTime.Now;
}
然后在form里的button_click事件里想引用这个textbox,请哪位大侠指点下```
------解决方案--------------------1、textbox设置为全局变量
2、me.controls........找到该控件
------解决方案--------------------Control.FindControl是BS下专有的。 System.Web.UI 命名空间
实际上用全局变量最为简单的;