多按钮循环更改属性问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 15:13:07
C#写的Windows应用程序,定义了一系列按钮,如下:
private System.Windows.Forms.Button btUrl6;
private System.Windows.Forms.Button btUrl5;
private System.Windows.Forms.Button btUrl4;
private System.Windows.Forms.Button btUrl3;
private System.Windows.Forms.Button btUrl2;
private System.Windows.Forms.Button btUrl1;
private System.Windows.Forms.Button btUrl0;
现在希望在程序中循环更改按钮的 Text 属性。
如:
for(int numUrl = 0;numUrl<20;numUrl++)
{
btUrl.?????. = ds.Tables["UrlName"].Rows[numUrl][0].ToString();这里如何写????
}
把btUrl0.Text赋值为ds.Tables["UrlName"].Rows[0][0].ToString();
把btUrl1.Text赋值为ds.Tables["UrlName"].Rows[1][0].ToString();
把btUrl2.Text赋值为ds.Tables["UrlName"].Rows[2][0].ToString();
以此类推。
小弟不才,望高手不吝赐教!!!!!
附:窗体上不仅仅只有这些按钮,还有其他按钮:
private System.Windows.Forms.Button btRMailLed;
private System.Windows.Forms.Button btRMail;
private System.Windows.Forms.Button btSMailLed;<

WinForm啊.一样的
int i=0;
foreach(Control button in this.Controls)\\循环每一个窗体上的控件
{
if (button.GetType().ToString() == "System.Windows.Forms.Button")\\判断控件类型是否为Button
{
((Button)button).Text = ds.Tables["UrlName"].Rows[i][0].ToString();
i++;
}
}

------------------------------------------
int i = 0;
foreach (System.Web.UI.Control c in this.FindControl("form1").Controls)
{
if (c is Button)
{
((Button)c).Text = ds.Tables["UrlName"].Rows[i][0].ToString();
i++;
}
}