更新时间:2023-12-05 09:43:40
^ ]
重要的是,请参见 ^ ].
Best suited for you[^]
And importantly, see this[^] also.
您可以看到此
您可以使用占位符根据数据库中的数据在运行时创建控件.
使用PlaceHolder ...
像:
You can use Place Holder to create Controls at Runtime according to the Data into your database.
Use PlaceHolder...
like :
string s1 = "your query ";
SqlDataAdapter ad1 = new SqlDataAdapter(s1,con);
DataSet ds1 = new DataSet();
ad1.Fill(ds1);
if (ds1.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
Label l = new Label(); // one label created at Runtime
Label lbl = new Label(); // second label created at runtime
l.ID = "l" + i.ToString(); // give ID to the first Label
l.ForeColor = System.Drawing.Color.Orange;
lbl.ID = "lbl" + i.ToString(); // give ID to the Second Label
l.Text = ds1.Tables[0].Rows[i][0].ToString(); // set text to the first label
lbl.Text = ds1.Tables[0].Rows[i][1].ToString(); // set text to the second label
PlaceHolder1.Controls.Add(l); // add control to the Placeholder
PlaceHolder1.Controls.Add(new LiteralControl("<br />")); // use for break one line
PlaceHolder1.Controls.Add(lbl); // add control to the placeholder
PlaceHolder1.Controls.Add(new LiteralControl("<br />"));
}
}