Quick and dirty asp.net DropDownList selection required validation

by Andrew Jackson 23. October 2006 19:00

I needed to do the usual thing, present a drop down list with the first item as a fake one being something like "-- Choose a Category --"

I jumped straight in and started thinking about custom validation etc etc and lost the will to live very quickly - considering this was just supposed to be a quick knock up project.

Then I found this little snippet, using the RequiredFieldValidator you can specify an InitialValue, put this to be your "-- Choose a Category --" and your away, it won't validate unless it's something other than that!

OK, it's not the most elegant solution, I'd prefer value, or even item being 0 comparison but it does in a push and worth remembering.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.net | Development

Comments are closed

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen