日期:2014-05-17 浏览次数:20476 次
//生成表
TableRow tableRow = new TableRow();
for (int i = 1; i < 4; i++)
{
//生成行
TableRow tableRow = new TableRow();
//cell
TableCell cellBody = new TableCell();
//生成第一个下拉列表控件
ListControlBase comboBox = (ListControlBase)ListControlBase.Create(Page, "ComboBoxControl");
//给下拉列表控件添加选项(lstItem是在for外面定义的一个ListItemCollection变量)
foreach (ListItem item in lstItem)
{
comboBox.Items.Add(item);
}
Control control = (Control)comboBox;
control.ID = "Field" + i;
//将控件放到cell中
AddControl(control);
cellBody.Controls.Add(control);
//第二个下拉列表控件
ListControlBase comboBox2 = (ListControlBase)ListControlBase.Create(Page, "ComboBoxControl");
comboBox2.ID = "Sort" + i;
//给下拉列表控件添加选项
comboBox2.AddItem("选项1","1");
comboBox2.AddItem("选项2","2");
//将控件放到cell中
AddControl(control2);
cellBody.Controls.Add(control2);
tableRow.Cells.Add(control2);
table.Rows.Add(tableRow);
}
//RecordSet是取到的值
foreach (Record record in RecordSet)
{
//取出来的值会是1或2或3
string order = record.GetString(tableName.Order);
string id = "Field" + order;
//controls是所有控件的集合
if (controls.ContainsKey(id))
{
((ListControlBase)controls[id]).Value = record.GetString(tableName.FieldValue);
}
id = "Sort" + displayOrder;
if (controls.ContainsKey(id))
{
((ListControlBase)controls[id]).Value = record.GetString(tableName.SortValue);
}
}