Gridview中的文本框验证 [英] Textbox validation in Gridview

查看:49
本文介绍了Gridview中的文本框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我是.Net的新手.
我有这个问题.
我在网格外部有一个文本框,其中保留了一些整数值(ProductID范围)
在网格内部,我有一个taxtbox,仅需输入小于或等于网格外部文本框中的值的整数值即可.

我尝试使用比较验证器和正则表达式验证器,但无法获得所需的输出.

任何帮助请..
在此先感谢....

Hi!
I am new to .Net.
I have this problem.
I had a textbox outside grid which maintains some integer value (ProductID range)
Inside the grid I have taxtboxes which needs to be entered only the integer values less than or equal to the value in the textbox outside the grid.

I tried using Compare validator and regex validatior, But unable to get the output what I want.

Any help Please..
Thanks in advance....

推荐答案

最简单的是如果您使用Javascript/jQuery来做到这一点.

将Grid文本框的onchange事件连接到Javascript方法.在那比较输入的值,并根据该值显示提示或采取任何必要的措施.
Easiest would be if you use Javascript/jQuery to do that.

Have a onchange event of Grid textbox wired up to a Javascript method. In that compare the value entered and based on it display the prompt or take any necessary action.


使用Javascript.

假设外部文本框的ID为txtoutside.

现在OnBlur OnChange event write

onchange ="javascript:return checkValue(this);"

Use Javascript.

Say the id of the outside textbox is txtoutside.

Now OnBlur or OnChange event write

onchange ="javascript:return checkValue(this);"

function checkValue(obj)
{
   if(obj){
      var elemoutside = document.getElementById(''txtoutside'');
      var thistextval = parseInt(obj.value);
      var outsideval = parseInt(elemoutside);
      if(outsideval <= thistextval) {
          
          return true;
      }
   }
   alert(''Invalid entry'');
   return false;
}





this would help I think.


您需要在模板字段"中的文本框的keyPress事件上编写javascript
只需在脚本中使用event.keychar来检查按键是否被按下.
仅允许数字键(keyCode = 47-56)

问候
You need to write the javascript on keyPress event of textbox which is in Template Field
Just use event.keychar in script to check whcih key get pressed.
allow only numric keys (keyCode = 47-56)

regards


这篇关于Gridview中的文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆