抛出的异常信息:异常详细信息:
System.ArgumentOutOfRangeException: “ddlTotalCostDiscount ”有一个无效 SelectedValue,因为它不在项目列表中。
原先给DropDownList这样赋值:
this.ddlTotalCostDiscount.SelectedValue = obj.TotalCostDiscount.ToString();
改成这样赋值:
ddlTotalCostDiscount.SelectedIndex = ddlTotalCostDiscount.Items.IndexOf(ddlTotalCostDiscount.Items.FindByValue(obj.TotalCostDiscount.ToString()));
就是如果通过FindByValue没有找到指定项则为null,而Items.IndexOf(null)会返回-1.