繁体   English   中英

在DataBound GridView上进行RegularExpression验证

[英]RegularExpression Validation on a DataBound GridView

是否可以验证已经绑定的gridview?

A | B | C | D
2 | 3 | a | 5

例如,我想检查列中的数据是否为非字母。 在这种情况下,我想突出显示或告诉我第2列第2行中有一个字母。

这样的事情可以解决问题。

Regex numeric = new Regex(@"^\d+$");

void GridView_RowDataBound(Object sender, GridViewRowEventArgs e) {
    // check out all cells in the current row
    foreach(var cell in e.Row.Cells) {
        // do some validation thingy
        if(!numeric.Match(cell.Text).Success) {
             cell.CssClass = "error"; // put error class on the cell
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM