因此,我有一個動態構建的表,它爲數據庫中的每臺計算機添加行。每行包含4列,並且向表中添加了2列,它們包含一個RadComboBox,使用戶能夠選擇來自數據庫的某些值。如何從動態構建的組合框中獲取選定的值
該構建每一行表
private void AddNewRow1(Machine Machine)
{
//start a new row
TableCell site = new TableCell();
TableCell name = new TableCell();
TableCell type = new TableCell();
TableCell model = new TableCell();
TableRow tr = new TableRow();
Literal breakline = new Literal();
breakline.Text = "<br />";
Literal breakline1 = new Literal();
breakline1.Text = "<br />";
//site name column
site.RowSpan = 2;
site.Controls.Add(AddSiteField(Machine));
tr.Controls.Add(site);
//machine name
name.RowSpan = 2;
name.Controls.Add(AddMachineField(Machine));
tr.Controls.Add(name);
//machine type name
type.RowSpan = 2;
type.Controls.Add(AddMachineTypeField(Machine));
type.Controls.Add(breakline);
type.Controls.Add(AddTypeComboBox());
tr.Controls.Add(type);
//machine model name
model.RowSpan = 2;
model.Controls.Add(AddMachineModelField(Machine));
model.Controls.Add(breakline1);
model.Controls.Add(AddModelComboBox());
tr.Controls.Add(model);
AssignPlaceHolder.Controls.Add(tr);
}
的方法,在模型和類型控制AddModelComboBox()或AddTypeComboBox()該方法是如下:
private RadComboBox AddModelComboBox()
{
RadComboBox MachineModelCombo = new RadComboBox();
machineModel = inputsService.GetMachineModelList(SiteID);
foreach (MachineModel MachineModel in machineModel)
{
if (MachineModel.Name != "NULL")
{
MachineModelCombo.Items.Add(new RadComboBoxItem(MachineModel.Name, MachineModel.ID));
}
}
MachineModelCombo.EnableLoadOnDemand = true;
MachineModelCombo.EmptyMessage = "Select a Machine Model";
return MachineModelCombo;
}
表工作正常,並且被正確地建造。 如果我有下面的代碼我的問題已經做得到這些動態地構建組合框的值:
protected void Update_Click(object sender, EventArgs e)
{
string MachineTypeID;
string MachineModelID;
machine = inputsService.GetMachineSiteDetails(SiteID);
foreach (Machine Machine in machine)
{
try
{
RadComboBox machineTypeComboBox = new RadComboBox();
RadComboBox machineModelComboBox = new RadComboBox();
MachineTypeID = machineTypeComboBox.SelectedValue;
MachineModelID = machineModelComboBox.SelectedValue;
inputsService.UpdateMachineModels(Machine.ID, MachineTypeID);
inputsService.UpdateMachineTypes(Machine.ID, MachineModelID);
}
catch (Exception ex)
{
{
logger.ErrorFormat(
"Update_Click exception occurred when attempting to update the database {0}", ex);
}
}
}
我的問題是,我怎麼能得到一個動態構建radcombobox控件選擇的值?
注:
inputsService.UpdateMachineModels(Machine.ID, MachineTypeID);
inputsService.UpdateMachineTypes(Machine.ID, MachineModelID);
這兩條線是Web服務調用一個DB API取決於在網頁中選擇的項目進行更新到數據庫中。任何以inputsService開頭的電話都是如此。*
任何幫助或建議都非常感謝。
感謝
您是否循環遍歷在更新事件中創建的錶行? –
它通過對機器對象中找到的每個機器進行循環,這是通過調用數據庫獲得的。 – James213