ListControl SelectedItem Validator
page 2 of 2
by CENK CIVICI
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 12877/ 24
Article Contents:

The Code

So enough with the talk lets take a look at the code.

 using System;
 using System.Web.UI;
 using System.Web.UI.WebControls;
 
 
 namespace MyValidations
 {
 
  [DefaultProperty("ErrorMessage")]
  public class RequiredSelectedItemValidator : System.Web.UI.BaseValidator 
  {
   private ListControl _listctrl;
 
   protected override bool ControlPropertiesValid()
   {
    Control ctrl = FindControl(ControlToValidate);
    
    If (ctrl != null) 
     _listctrl = ctrl as ListControl;
     return (_listctrl != null);  
    else 
       return false;  // raise exception
   }
 
   protected override bool EvaluateIsValid()
   {
   
    return (_listctrl is DropDownList) ? (_lisctrl.SelectedIndex != 0) : 
               ( _lisctrl.SelectedIndex != -1);
   }
  }
 }
 


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-19 11:15:43 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search