62,046
社区成员
发帖
与我相关
我的任务
分享
protected void vg_rowbound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType != DataControlRowType.Footer)
{
TextBox tb = e.Row.FindControl("InputId") as TextBox;
if (tb != null)
tb.MaxLength = 8;
// 或者用下面的方法处理,假设GridView中最后一列操作列有一个Update的按钮,编辑值后,点击Update按钮保存修改,在这里为update按钮添加校验js
LinkButton lb = e.Row.FindControl("UpdateBtn") as LinkButton;
if (lb != null && tb != null)
lb.Attributes.Add("onclick", "javascript:if('" + tb.Text.Trim() + "'.length > 8) return;");
}
}