Search This Blog

Tuesday, July 26, 2011

Blank Default Value in Combobox

Hi all


I am a little confused with an issue regarding a combo box being displayed on my asp.net webpage.


All I want to do it have a blank default value at the top of a list which is bound with a database, which also prevents the user from selecting it, for example “–Select One–”


I have included the following code in the DropDownList asp code:



I have also set AppendDataBoundItems property to true (as the combobox AutoPostBack property is true) as well as the CausesValidation being set to true.


However my problem is, this does display but when this blank value “–Select One–” is chosen, the page errors because obviously there isn’t a value “Select One”







Server Error in '/' Application.
--------------------------------------------------------------------------------

Conversion failed when converting the varchar value '--Select One--' to data type int.
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.Data.SqlClient.SqlException: Conversion failed when converting the varchar value '--Select One--' to data type int.




I don’t want anything to happen when the user selects the “–Select One–” option, as obviously this might happen accidenly when the user is using it.


Thanks in advance!

http://bit.ly/qRrGzl

No comments:

Post a Comment