2.
擷取 GridView內部的某一列、某一欄位的值
欄位值
 string d = (string)e.NewValues["LastName"];
string d = (string)e.NewValues["LastName"];
 if (d.Length < 5)
 {
 this.ClientScript.RegisterClientScriptBlock(this.GetType(),
"msg", "");
 e.Cancel = true;
}
            else
            {
               
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "msg",
"");
            }
欄位 input 名稱
GridView1.Rows[e.RowIndex].Cells[3].Controls[0].ClientID
--------------  CustomValidator  驗證 類別 使用
 --------------
CustomValidator _CustomValidator = new CustomValidator(); 建立類別
_CustomValidator.ControlToValidate = this.txtName.ID; 控制名稱
_CustomValidator.ClientValidationFunction = "check"; Function 名稱
_CustomValidator.ErrorMessage = "請輸入資料"; 錯誤訊息文字
_CustomValidator.ValidateEmptyText = true; 是否驗證空白(一定要選)
_CustomValidator.EnableClientScript = true; 驗證使用者是否把Script 關閉
_CustomValidator.ServerValidate += new
ServerValidateEventHandler(CustomValidator1_ServerValidate); 註冊 Code Server端驗證
Page.Form.Controls.Add(_CustomValidator); 將類別 放置Form 裡面
Code
        private void
CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (txtName.Text.Length
< 5)
            {
               
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "msg",
"");
               
args.IsValid = false;
            }
            else
               
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "msg",
"");
        }
Html
scriptfunction check(source,
arguments){
    if(arguments.Value.length<5){
        alert("長度要大於4");
       
arguments.IsValid = false;
    }
    else{;
    }
}
script
2. 擷取 GridView內部的某一列、某一欄位的值
C#語法 -- TextBox my_test_time = (TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0];
VB語法 -- Dim my_test_time As TextBox = GridView1.Rows(e.RowIndex).Cells(4).Controls(0)
              或是用 CType(GridView1.Rows(e.RowIndex).Cells(4).Controls(0), TextBox)來作轉換,強制轉成TextBox型態