MSDN這篇很有用
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.tableheaderrow%28v=vs.110%29.aspx
有空試試
http://stackoverflow.com/questions/9103949/add-asp-controls-to-a-table-dynamically
The following assumes you have a blank ASP:Table on your page with some defined rows (just for show really).
protected void Page_Init(object sender, EventArgs e)
{
foreach (TableRow row in this.Table1.Rows)
{
foreach (TableCell cell in row.Cells)
{
Button btn = new Button();
btn.Text = "Some Button";
btn.Click += new EventHandler(btn_Click);
cell.Controls.Add(btn);
}
}
}
void btn_Click(object sender, EventArgs e)
{
((Button)sender).Text = "Just Clicked";
}
=============================================================
NET 3.5 用下面的方法加
ListItem
List<ListItem> ListZip = new List<ListItem>();
foreach (var item in q)
{
ListItem li = new ListItem(item.Zip_Name.Trim(), item.Zip_Code.Trim());
ListZip.Add(li);
}
ddl.Items.AddRange(ListZip.ToArray());
====================================================================
NET 2.0 用下面的方法加
ListItem
ListItem[] ListItemArray = new ListItem[ds.Tables["T_Zip"].Count()];
for (int i = 0; i < ds.Tables["T_Zip"].Count; i++)
{
ListItemArray[i] = new ListItem(
ds.Tables["T_Zip"].Rows[i].["Zip_Name"].ToString().Trim(),
ds.Tables["T_Zip"].Rows[i].["Zip_Code"].ToString().Trim()
);
}
ddl.Items.AddRange(ListItemArray);
沒有留言:
張貼留言