Saving dropdownlist value inside the repeater?
I already retrieved my database(DescriptionCode) on dropdownlist
inside on a repeater.
Now, I'm trying to save/add/insert on my database the selected value of dropdownlist but i
failed.
Any assistance gratefully received. Thanks!
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);
}
What about the cmdSave button, is that is inside the Repeater
You need to find out myDDL inside each row and for each of them you need to get this value.
foreach (RepeaterItem rptItem in RepeaterName.Rows)
{
DropDownList myDDL = (DropDownList)rptItem.FindControl("myDDL");
}
DropDownList myDDL = (DropDownList)GeneralRepeater.Items[indexvalue].FindControl("GeneralDDL");
oPlanofCareSave.DiagnosesCode = myDDL.SelectedValue;
it is easy to do it like that
精彩评论