应用C#自动生成的控件

2025-02-02 22:31:54
推荐回答(4个)
回答1:

最好用客户端控件,循环命名即可,后台生成的服务器端控件在客户端不能使用。
例子:

string strsql = "select * from [ZF]专业建设 where '" + strSD + "' = " + strsysid;

KBaseServerDAL kal = new KBaseServerDAL();
RecordSet rs = kal.GetDataSetBySQL(strsql);

if (rs != null && rs.GetCount() > 0)
{
for (int i = 0; i < rs.GetCount(); i++)
{
if (str3 == "任课教师")
{
SelectOther1(rs.GetValue(str3));
}
else if (str3 == "课程名称")
{
SelectOther2(rs.GetValue(str3));
}
else
{
htmlBody += "
  " + str3 + " " + rs.GetValue(str3) + "

";
}
rs.MoveNext();
}
}

回答2:

(TextBox)Panel1.FindControls("Textname").Text="应该是这样的";

回答3:

Label labela;

for (int i = 0; i < 5; i++)
{
labela = new Label();
labela.Name = "temp" + i.ToString();
//labela.ID = "temp" + i.ToString();
labela.Text = "temp" + i.ToString();

this.Controls.Add(labela);
}
this.textBox1.Text = ((Label)(this.Panel1.Controls["temp0"])).Text;

回答4:

protected void mytemp()
{ Label labela;
for (int i = 0; i < 5; i++)
{
labela = new Label ();

labela.ID = "temp" + i.ToString ();
labela.Text = "temp" + i.ToString ();

if(i==3){textBox1.text= labela.text;} //加上这个判断就可以了

Panel1.Controls.Add(labela);
}
}