0
在我的Page_Init方法中,我創建了1個checkboxlist(填充項目)和幾個下拉列表,等於checkboxlist中的項目數量(6checkboxlistitems - > 6 dropdownlists)。從幾個下拉列表中獲取值
這兩個項目的下拉列表都與數據有關(項目代表每週的每一天,下拉列表中填充了一天的4個時間段)。我爲每個項目創建一個下拉列表,併爲其指定id = item.text。從Page_Init方法
代碼:
foreach (ListItem item in chkListContact.Items)
{
ddlTimePeriod = new DropDownList();
ddlTimePeriod.ID = item.Text;
ddlTimePeriod.CssClass = "dropdownlistContact";
ddlTimePeriod.DataSource = datasrcTimePeriod;
ddlTimePeriod.DataTextField = "TimePeriodName";
ddlTimePeriod.DataValueField = "TimeToCallID";
ddlTimePeriod.DataBind();
dllPanel.Controls.Add(ddlTimePeriod);
dllPanel.ID = "dllPanel";
}
代碼從BUTTON_CLICK:
foreach (ListItem item in chkListContact.Items)
{
//
if (item.Selected)
{
//Here I want to get the values from the selected items and corresponding dropdownlist value and send it to database
cmdTimeToCall.Parameters.Clear();
cmdTimeToCall.Parameters.Add("PersonId", personid);
cmdTimeToCall.Parameters.Add("DayOfWeekId", Convert.ToInt32(item.Value));
cmdTimeToCall.Parameters.Add("TimeToCallId", --VALUE FROM DROPDOWNLIST OF CORRESPONDING ITEM --);
}
}
選擇相應的項目時,你怎麼能採取從每個下拉列表的價值?
thx巴拉,我不知道FindControl():) – Thomas