在ItemDataBind事件里加If e.Item.ItemIndex >= 0 Then
    Dim btn As Button = e.Item.Cells(x).Controls(y)
    If btn.CommandName = "Update"
       btn.Attributes("onclick") = "javascript:..........."
    End If
End If

解决方案 »

  1.   

    yes
    js中判断btn.Attributes("onclick") = "javascript:return checkInput()"
    <script>
    function checkInput()
    {
     if(!confirm("修改?"))
       return false;  //返回false就不会更新了
    }
    </script>
      

  2.   

    >>>>问题是我在保存前需要判断某些列是否为空you can use RequiredFieldValidator inside EditItemTemplateor if you insist on using client side script, you could try something like this:in the server side, you do the following to keep track of which row is being edited:Page.RegisterHiddenField("EditItemIndex",DataGrid1.EditItemIndex.ToString());on the client side, <script>
    function checkInput()
    {
      var tbl = document.getElementById("DataGrid1");
      var tr = tbl.rows[document.forms[0].elements["EditItemIndex"] + 1];
      var inputs = tr.all.tags("INPUT");
      for (var i=0; i < inputs.length; i++)
      {
            if (inputs[i].type == "text" && inputs[i].value == "")
            {
                   alert(inputs[i] + " cannot be empty");
                   return false;
            }
       }
    }
    </script>