在gridview的更新中更新某个字段是设置该字段输入只能是数字,
思路是为输入的那个文本框添加事件,用javascript高效的正则表达式在客户端进行判断,
详细代码
protected void gvInfoList_RowEditing(object sender, GridViewEditEventArgs e)
{
//标记编辑行
gvInfoList.EditIndex = e.NewEditIndex;
//绑定数据
gvInfoList.DataSource = SelectDataTable();
gvInfoList.DataKeyNames = new string[] { "StuFileIDStr" };
gvInfoList.DataBind();
//为编辑行中的某一列添加事件,用javascript、正则表达式来实现该功能
((TextBox)(gvInfoList.Rows[e.NewEditIndex].Cells[6].Controls[0])).Attributes["onkeyup"] = @"this.value=this.value.replace(/\D/g,'')";
((TextBox)(gvInfoList.Rows[e.NewEditIndex].Cells[6].Controls[0])).Attributes["onafterpaste"] = @"this.value=this.value.replace(/\D/g,'')";
}
项目中的需要,费了我一会儿时间,记录一下