GridviewCell十进制接受问题 [英] GridviewCell decimal accept issue

查看:101
本文介绍了GridviewCell十进制接受问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何像我对Textbox那样使Gridview单元格只接受一个小数点?

Hi,

how can I make Gridview cell from accepting only one decimal point like I did for Textbox?

private void txtDiscount_KeyPress(object sender, KeyPressEventArgs e)
{
  if (e.KeyChar == '.')
  {
    if (txtDiscount.Text.Contains('.'))
      e.Handled = true;
  }
}



但是对于gridview单元,它不起作用.您可以帮我吗?



But for the gridview cell it''s not working. Can you help me?

推荐答案

对于Gridview中的子控件,我们没有直接事件

所以首先我们必须获得像这样的TextBox值

For Child Controls in the Gridview we don''t have the direct events

so first we have to get the TextBox value like this

TextBox Foottxtboxunitrate = (TextBox)ProjectOnFormGrid.FooterRow.FindControl("Foottxtboxunitrate");



然后



then

Regex amountpattern = new Regex(@"^[0-9]*(\.)?[0-9]{0,1}?


" ); 如果(amountpattern.IsMatch(Foottxtboxunitrate.Text.Trim())== false ) { lblError.Text = " true ; Foottxtboxunitrate.Focus(); 返回; }
"); if (amountpattern.IsMatch(Foottxtboxunitrate.Text.Trim()) == false) { lblError.Text = "Enter valid Rate amount with maximum 1 decimal places. "; lblError.Visible = true; Foottxtboxunitrate.Focus(); return; }


您可以使用javascript
来实现
使用JavaScript进行GridView计算-格式设置和验证 [ ^ ]
You can achieve that by using javascript

GridView Calculation with JavaScript - Formatting and Validation[^]


这篇关于GridviewCell十进制接受问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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