我有一個不能用於編輯目的的下拉列表。當按鈕Edit在數據存在的listview內部被點擊時,數據應該返回到下拉列表和其他文本框,其中該表格位於listview之外。將數據傳回文本框是可以的。問題是我想編輯的dropdownlist數據被添加到dropdownlist中作爲另一個記錄。請拍一張照片,我必須重新選擇正確的照片。否則,選擇的數據(例如圖片中的12月)沒有數據值字段,如果我沒有選擇12月底,並且點擊更新按鈕,它將停止運行。這是我的代碼爲dropdownlist幾個月。任何幫助表示讚賞。謝謝。將數據傳回Dropdownlist的錯誤asp .net webform
public void BindMonth()
{
ddlStartMonth.DataSource = objUIHelpers.GetAllMonths();
ddlStartMonth.DataTextField = "StartMonthName";
ddlStartMonth.DataValueField = "MonthId";
ddlStartMonth.DataBind();
ddlStartMonth.Items.Insert(0, "Select Start Month");}
然後,我把這種方法在頁面加載這樣。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindMonth();
}
}
這是列表視圖數據項編輯
protected void lvEducation_ItemCommand(object sender, ListViewCommandEventArgs e)
{
switch (e.CommandName)
{
//Delete Method will be fired when command name "Delete" inside Listview is clicked.
case ("Delete"):
int EducationId = Convert.ToInt32(e.CommandArgument);//pass Id of Experience to identify datarow to delete
// DeleteEducationById(ExperienceId);//Call bind to delete method and pass ExperienceId as argument
break;
//Edit Method will fired when command name "Edit" inside Listview is clicked.
case ("Edit"):
EducationId = Convert.ToInt32(e.CommandArgument); //pass Id of Experience to identify datarow to edit
BindEducationDataToEdit(EducationId);//Call bind to edit method and pass ExperienceId as argument
break;
}}
這是方法的一部分觸發回傳數據進行編輯。
public void BindEducationDataToEdit(int EducationId)
{
Education edu = objJFUserBAL.GetEducationByIdToEdit(EducationId);
txtAdditionalInfo.Text = edu.AdditionalInfo.ToString();
ddlEndMonth.SelectedItem.Text = edu.mo.EndMonthName;
}
非常感謝。它適用於您的代碼。我的問題剛剛解決。我在你的上面增加了一行代碼。 'ddlEndMonth.ClearSelection();'清除原始選擇;否則,它會拋出ddl中的多重選擇異常。謝謝。 – jkhaung