

运行时出现以上错误:
Cannot have multiple items selected in a DropDownList.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Web.HttpException: Cannot have multiple items selected in a DropDownList.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
解决的办法有两种:
1.DropDownList数据绑时,设置某个项被择前,加如下代码:

设置某项被选择的所以代码如下:


2.另一种通过SelectedIndex设置被选择的项,代码如下:

DropDownList绑定时,默认的是选择第一项为选择项,ddlMagazine.ClearSelection()可以清除选择项,然后重新设置选择项。