public void FindControl(Control.ControlCollection c) { foreach (System.Windows.Forms.Control control in c) { if (control is Label) { Label l= control as Label; int i= int.Parse(Label.Id.ToString().Substring(3,1)); l.Text=(i*9-5).ToString(); } } }
for (int i = 1; i <= 10; i++) { Label lbl = this.Controls.Find("LAB" + i.ToString()) as Label; if (lbl!=null) { lbl[0].Text = (i * 9 - 5).ToString(); } } this.Controls.Find()是方法,不是属性!
纠正: for (int i = 1; i <= 10; i++) { Label lbl = this.Controls.Find("LAB" + i.ToString()) as Label; if (lbl!=null) { lbl.Text = (i * 9 - 5).ToString(); } } Find()是方法,不是属性!
{
Label[] lbl = (Label[])this.Controls.Find("LAB" + i.ToString(), true);
if (lbl.Length == 1)
{
lbl[0].Text = (i * 9 - 5).ToString();
}
}
for (int i = 1; i <= 10; i++)
{
Control[] ctls = this.Controls.Find("LAB" + i.ToString(), true);
if (ctls.Length == 1 && (ctls[0] is Label))
{
(ctls[0] as Label).Text = (i * 9 - 5).ToString();
}
}
{
(this.Controls["LAB" + i.ToString()] as Label).Text = (i * 9 - 5).ToString();
}
你先试过了再回复this.Controls["str"]其实里面的str也只是个索引值罢了,和C++里面的宏定义相似
D:\qnyd\vote\vote.aspx.cs(215): 参数“1” : 无法从“string”转换为“int”
{
foreach (System.Windows.Forms.Control control in c)
{
if (control is Label)
{
Label l= control as Label;
int i= int.Parse(Label.Id.ToString().Substring(3,1));
l.Text=(i*9-5).ToString();
}
}
}
{
Label lbl = this.Controls.Find("LAB" + i.ToString()) as Label;
if (lbl!=null)
{
lbl[0].Text = (i * 9 - 5).ToString();
}
}
this.Controls.Find()是方法,不是属性!
for (int i = 1; i <= 10; i++)
{
Label lbl = this.Controls.Find("LAB" + i.ToString()) as Label;
if (lbl!=null)
{
lbl.Text = (i * 9 - 5).ToString();
}
} Find()是方法,不是属性!
{
Label lbl = (Label)this.Controls.Find("LAB" + i.ToString());
lb1.text=(i*9-5).toString();
}
{
Label lbl = this.FindControl("LAB" + i.ToString()) as Label;
if (lbl!=null)
{
lbl.Text = (i * 9 - 5).ToString();
}
}