javascript in grid databound (code behind)

Sep 15 2014 11:50 AM
I have one text box in my grid and need to set validation like should allow numbers upto 
3 digits only 

validation should be done from code behind (grid row databound)

i have javascript its working fine .but i need same js in row data bound 



<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-CssClass="assignborder">
    <headertemplate>Interval</headertemplate>
    <itemtemplate><asp:TextBox ID="txtInterval" runat="server" onkeyup="validate()l"></asp:TextBox></itemtemplate>
</asp:TemplateField>





function validate()
{
  //getting key code of pressed key
  var keycode = (key.which) ? key.which : key.keyCode;


   
   var intrval = document.getElementById('ctl00_Mdi_grdabc_txtInterval');

  //comparing pressed keycodes
  if (!(keycode==8 || keycode==46)&&(keycode < 48 || keycode > 57)) {
     alert("Please Enter Digits only");
     return false;
     }
    else
   {
    //Condition to check textbox contains 3 numbers or not
      if (intrval.value.length < 3)
      {
        return true;
      }
      else 
      {
        alert("Interval Should not be greater than 3 digits");
        return false;
      }
    
   }
}
 

Answers (5)