在转发器中保存下拉列表值?

时间:2011-05-24 04:56:21

标签: c# drop-down-menu repeater

我已经在转发器上的dropdownlist内检索了我的数据库(DescriptionCode)。

现在,我正在尝试在我的数据库中保存/添加/插入下拉列表的选定值,但我

失败。

感激地收到任何帮助。谢谢!

 protected void GeneralRepeater_OnItemDataBound(object sender,
                                               RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item ||
            e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DropDownList myDDL = (DropDownList)e.Item.FindControl("GeneralDDL");
            Diagnosis oDiagnosis = new Diagnosis();
            PlanOfCare oPlanOfCare = new PlanOfCare();
            DataView dv = new DataView(oDiagnosis.GetDiagnosis());
            myDDL.DataSource = PatientDiagnosis1;
            myDDL.DataTextField = "DiagnosisCode";
            myDDL.DataValueField = "DiagnosisCode";
            myDDL.DataBind();

            //PUT AN EMPTY FIELD FOR DROPDOWNLIST
            ListItem LI = new ListItem("", "");
            myDDL.Items.Insert(0, LI);
            myDDL.SelectedValue = "0";



        }
    }


 protected void cmdSave_Click(object sender, EventArgs e)
    {
    oPlanofCareSave.DiagnosesCode = //[1]this must the selected value of dropdownlist inside of repater
    PlanSave(ooPlanofCareSave);
}

2 个答案:

答案 0 :(得分:5)

cmdSave按钮怎么样,就在Repeater里面

您需要在每行中找到myDDL,并且每个行都需要获取此值。

foreach (RepeaterItem rptItem in RepeaterName.Rows)
{
         DropDownList myDDL = (DropDownList)rptItem.FindControl("myDDL");
}

答案 1 :(得分:4)

DropDownList myDDL = (DropDownList)GeneralRepeater.Items[indexvalue].FindControl("GeneralDDL");

oPlanofCareSave.DiagnosesCode = myDDL.SelectedValue;

很容易就这样做