我有一个不能用于编辑目的的下拉列表。当按钮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