how can i restrict the non integers entered on the textbox on the gridview using javascript

Hi agz86,

I hope I can help you......

In GridView template :

<asp:templatefield headertext="Amount">
   <itemstyle borderstyle="None" font-size="8pt" width="20px" />
   <headerstyle font-bold="False" width="65px" font-size="8pt"/>
         <itemtemplate>
         <asp:TextBox id="Amount" text='<% # eval("AMOUNT") %>' runat="server" width="65px"  font-size="8pt" onkeypress="keyDownNumber()" </asp:TextBox>                                                                                 
         </itemtemplate>
    </asp:templatefield>

In JavaScript :

<script language="Javascript" type="text/javascript">   
function keyDownNumber()
{ 
    var key;    
    if(navigator.appName == 'Microsoft Internet Explorer')
        key = event.keyCode;
    else
        key = event.which
        
    if ( !(key >= 48 && key <= 57) && key != 8 && key != 46 && key != 36 && key != 37)
    {
        event.returnValue = false;        
    }
}
</script>

Thanks,

Kusno

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.