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
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;
}
}
}

Abhishek KumarRank #510 · 4.8K reputationPosted Sep 15, 2014, 8:24 AM EDT
Seems some issue with the paste.
protected void gvPlanMaintenance_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
TextBox txt= (TextBox)e.Row.Cells[0].FindControl("txtInterval");
if (txt != null)
{
btnTest.Attributes.Add("onkeypress", "javascript:return Validate();");
}
}
Abhishek
Abhishek KumarRank #510 · 4.8K reputationPosted Sep 15, 2014, 8:23 AM EDT
hi, Please Try this. protected void gvPlanMaintenance_OnRowDataBound(object sender, GridViewRowEventArgs e) { TextBox txt= (TextBox)e.Row.Cells[0].FindControl("txtInterval"); if (txt != null) { btnTest.Attributes.Add("onkeypress", "javascript:return Validate();"); } } Hope this will help. Abhishekvamsidhar kotipalli50 reputationPosted Sep 15, 2014, 10:53 PM EDT
vamsidhar kotipalli50 reputationPosted Sep 15, 2014, 10:54 PM EDT
Abhishek KumarRank #510 · 4.8K reputationPosted Sep 16, 2014, 12:41 AM EDT
Cheers
Abhishek