0
votes

I have 3 dropdownlist which will have set of values from the database. In my page, I have different controls. I was planning to add this dropdownlist in a repeater control.

When a user selects a value, the value will be saved to the database, either by a save button inside the control or automatically.

Could you please let me know if this is possible? If yes, any code that can be shared would be helpful.

2

2 Answers

0
votes

Yes, it's possible. The trick is that the DataSource for the dropdownlists are separate than the DataSource of the Repeater.

0
votes

Here's the sample code:

protected void cmdSave_Click(object sender, EventArgs e)
{
 foreach (RepeaterItem ri in GeneralRepeater.Items)
        {
            switch (ri.ItemType)
            {
                case ListItemType.Item:
                case ListItemType.AlternatingItem:

                    DropDownList GetValue = (DropDownList)ri.FindControl("GeneralDDL");
                    var sSelectedValue = GetValue.SelectedValue;

                    for (int index = 0; index <= PocDiagnoses.MAX_DIAGNOSIS; index++)
                    {
                        foreach (RepeaterItem ri1 in GeneralRepeater.Items)
                        {
                            int iItemIndex = ri1.ItemIndex;
                            DropDownList myDDL = (DropDownList)GeneralRepeater.Items[index].FindControl("GeneralDDL");

                            FirstPlanOfCare.Diagnoses.Diagnoses[index] = new PatientDiagnosis(myDDL.SelectedValue, new SynergyOnSetDate(new System.DateTime(Year, Month, Day)), "01/02/2011"); //Insert Diagnosis Value

                        }
                    }
                    break;
            }
        }
        //Create
        Chart.AddPlanOfCare(FirstPlanOfCare);

}