RadGridView CELL Editing Validation.

2 posts, 0 answers
  1. Karthikeyan
    Karthikeyan avatar
    27 posts
    Member since:
    Aug 2011

    Posted 09 Dec 2011 Link to this post

    Hi Telerik Admin's,

    I've requirement in RadGridView.
    I'm adding a row dynamically in the gridview.
    The added row can be edit, while editing the row I want the user to restrict to enter ONLY ALPHA NUMERIC.
    Here I've pasted the code for restricting user enter special character. please have a look.
    As well as, is there any possibility to do the validation in each column cell of the newly added row.


         public bool IsAlphaNumeric(String strToCheck)
                Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]");
                return !objAlphaNumericPattern.IsMatch(strToCheck);

    Remove Special Characters :-

     public string RemoveSpecialChars(string input)
                return Regex.Replace(input, @"[^0-9a-zA-Z\._]", string.Empty);

    Please guide me to do this ASAP.

    Thanks in advance,
    Karthikeyan Manickam.

  2. Tyree
    Tyree avatar
    105 posts
    Member since:
    Dec 2006

    Posted 09 Dec 2011 Link to this post

    I am sure you are aware that you can put your logic in the setter of the particular column in question but this may not look as nice as you want as they can type anything and only on leaving the column does the data reflect the change. Another approach is to set the UpdateSourceTrigger=Explicit on the edit control (like a textbox) and then capture the appropriate event on the control to commit the data as they type. This can work but its a bit ugly and cumbersome.

    The approach I use is a custom behavior on the TextBox which basically ignores keystrokes that don't match the pattern defined. For me this has been the most trouble-free implementation. My textbox looks like:
    <TextBox MaxLength="11" Text="{Binding SomeValue}">
            <behaviors:LimitKeyPressToType InputType="Numeric" AllowNegative="True" FocusBehavior="SelectAll"/>
    The behavior is a single class to include in your project, if you care to try it I can post the code.

    You could also use Teleriks MaskedInput but I personally do not like how it looks and behaves.
Back to Top