Tuesday, March 01, 2005

dropdownlist databind error

The following error

ASP.NET dropdownlist Specified argument was out of the range of valid values. Parameter name: value

will occur if

1) Set a dropdownlist selectedvalue to some value - e.g. 123
2) Bind the dropdownlist to a datasource which does not contain the value 123

Solution:
Before binding, extract the selected value. Set dropdownlist.selectedvalue to nothing, then after binding, reinsert the value back. (Does not work if set dropdownlist.items.clear or setting selectedindex to -1)

Or correctly, should bind first, then assign selectedvalue




0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home