是否可以验证网格视图内的单元格bcoz我已经更新了单元格,但我不知道如何验证网格视图内的单元格.请给我一些选择 [英] Is it possible to validate the cells inside the grid view bcoz i hav updated the cells but i dono how to validate the cells inside grid view. Kindly suggest me with some options

查看:84
本文介绍了是否可以验证网格视图内的单元格bcoz我已经更新了单元格,但我不知道如何验证网格视图内的单元格.请给我一些选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以验证网格视图内的单元格,因为我已经更新了单元格,但我不知道如何验证网格视图内的单元格.请为我提供一些选择.

Is it possible to validate the cells inside the grid view bcoz i hav updated the cells but i dono how to validate the cells inside grid view. Kindly suggest me with some options.

推荐答案

将所有必需的验证器添加到标记中,并在RowDataBound中启用/禁用它们. 此示例使用比较验证器来验证测试值:
Add all your required validators to your mark up and enable/disable them in RowDataBound
this example use compare validator that validate a test value:
void Grd_RowDataBound(Object sender, GridViewRowEventArgs e)
{
  if(e.Row.RowType == DataControlRowType.DataRow)
  {
      DataRowView rowView = (DataRowView)e.Row.DataItem;
      String testValue = rowView["Test"];
      CompareValidator cv1 = (CompareValidator)e.Row.FindControl("cv1); // checks between 2-7
      CompareValidator cv2 = (CompareValidator)e.Row.FindControl("cv2); // checks true/false
      cv1.Enabled = testValue.ToUpper().Equals("ABC");
      cv2.Enabled = !cv1.Enabled;
  }
}


您可以通过在行数据绑定事件的那个gridview控件上应用js来做到这一点
这是一个简单的例子

you can do it by applying js on that gridview control on row data bound event
here is simple example

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
TextBox tbx0 = (TextBox)e.Row.Cells[0].Controls[1];

tbx0.Attributes.Add("onblur", "return JSFunction(" + tbx0.ClientID + ");"

}
}


如果它是动态gridview,请在edititem模板中尝试.

大小写ListItemType.EditItem:

TextBox field_txtbox = new TextBox();
field_txtbox.ID = FieldName;
field_txtbox.Text = String.Empty;
field_txtbox.Width = 60;
RequiredFieldValidator rfv =新的RequiredFieldValidator();
rfv.ID = field_txtbox.ID +有效";
rfv.ControlToValidate = field_txtbox.ID;
rfv.ErrorMessage =请输入值";
rfv.Display = ValidatorDisplay.Dynamic;
Container.Controls.Add(rfv);
hi if it is dynamic gridview try this in edititem template.

case ListItemType.EditItem:

TextBox field_txtbox = new TextBox();
field_txtbox.ID = FieldName;
field_txtbox.Text = String.Empty;
field_txtbox.Width =60;
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ID = field_txtbox.ID + "valid";
rfv.ControlToValidate = field_txtbox.ID;
rfv.ErrorMessage = "Please Enter Value";
rfv.Display = ValidatorDisplay.Dynamic;
Container.Controls.Add(rfv);


这篇关于是否可以验证网格视图内的单元格bcoz我已经更新了单元格,但我不知道如何验证网格视图内的单元格.请给我一些选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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