求助 在后台 把DropDownList添加到单元格中
各位大神 怎么在后台 把DropDownList添加到单元格中。table 和 DropDownList 都是在后台绘制的
------解决方案--------------------public void BindCongif()
{
this.Table1.Rows.Clear();
DataTable dt = new DataTable();
dt = GetDataTable();//获取数据源
if (dt != null)
{
int rowcount = GetRowCount(dt);//获取行数
int colcount = GetColCount(dt);//获取列数
for (int row = 1; row <= rowcount; row++)
{
TableRow tr = new TableRow();
for (int col = 1; col <= colcount; col++)
{
TableCell td = new TableCell();
DropDownList ddl = new DropDownList();
string id = "ddl_" + row + "_" + col;
ddl.ID = id;
ddl.DataTextField = "CellName";
ddl.DataValueField = "CellID";
ddl.DataSource = GetDllSource();//获取下拉框数据源
ddl.DataBind();
ddl.Items.Insert(0, new System.Web.UI.WebControls.ListItem("-未选择-", "0"));
foreach (DataRow dr in dt.Rows)
{
if (Convert.ToInt32(dr["Row"]) == row && Convert.ToInt32(dr["Col"]) == col)
{
ddl.SelectedValue = dr["CellID"].ToString();
}
}
td.Controls.Add(ddl);
td.Heigh