【发布时间】:2015-10-06 14:08:16
【问题描述】:
我有一个不能用于编辑目的的下拉列表。在存在数据的列表视图中单击“编辑”按钮时,数据应该传回下拉列表和表单位于列表视图之外的其他文本框。将数据传回文本框是可以的。问题是我要编辑的下拉列表数据作为另一条记录添加到下拉列表中。请在图片中掠夺,我必须重新选择正确的。否则,所选数据(例如图片中的十二月)没有数据值字段,如果我没有选择底部十二月并单击更新按钮,它将停止运行。这是我几个月的下拉列表代码。对此的任何帮助表示赞赏。谢谢。
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;
}
【问题讨论】:
标签: c# asp.net listview drop-down-menu webforms