Click here to Skip to main content
15,065,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every one I am faceing problem with gridview editing value-

Que:- How to restrict gridview column to accept only numbers at client side
Suppose there is two columns in gridview and i want that first column should take
alphabets and second should take numbers only...

I have tried onKeyPress event in asp page but not works...

waiting for your suggestion.
thanks in advance.

Try This......

Add columns in Grid control then in Column Properties -Group Format- Format Type select Numeric...
Use templated field with masked edit for a textbox in grid view, follow this link , to know use of maskedit ajax toolkit[^]

You can use AJAX FilterTextBoxExtender to filter the characters entered in the textbox.

Here is the sample code for you

<asp:ScriptManager ID="SM1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <asp:TextBox ID="txtNumeric" runat="server"></asp:TextBox>
                <ajax:FilteredTextBoxExtender ID="FTBE_txtNumeric" runat="server" FilterType="Numbers" TargetControlID="txtNumeric"></ajax:FilteredTextBoxExtender>
                <br />
                <asp:TextBox ID="txtAlphabet" runat="server"></asp:TextBox>
                <ajax:FilteredTextBoxExtender ID="FTBE_txtAlphabet" runat="server" FilterType="UppercaseLetters,LowercaseLetters" TargetControlID="txtAlphabet"></ajax:FilteredTextBoxExtender>

You can follow the below link for more queries[^]

Happy coding :)

May be u can user a REgularexpressionvalidator..

<asp:gridview id="mygrd" runat="server" visible="true" xmlns:asp="#unknown">
<asp:boundfield headertext="Alphabets">

<asp:templatefield headertext="OnlyNumbers">

<asp:textbox id="txtBox1" runat="server">
<asp:regularexpressionvalidator id="RegularExpressionValidator1">
ErrorMessage="Please enter numbers only"


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900