In my Page_Init method, I create 1 checkboxlist (filled with items) and several dropdownlists equal to the amount of items in checkboxlist (6checkboxlistitems -> 6 dropdownlists).
Both, items en dropdownlists are bounded to data (items represent each day of the week, dropdownlists are filled with 4 timeframes of a day). I create a dropdownlist for every item and give it id = item.text.
Code from the Page_Init method:
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";
}
Code from the 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 --);
}
}
How can you take the value from each dropdownlist when the corresponding item is selected?
1 Answer