Cancel a Datagrid rowcommand
I am trying to fix somebody elses code and this is my first ASP.NET dataVIEW experiance, basically I want to check that a textbox has a value, The DataVIEW has been coded so that on the "add/update" an ok/cancel开发者_运维技巧 button is used.
In the Rowcommmand I have detected the update successfully, found the text box, and varified the contents ..... but now I can't cancel the RowComand .. is there any way to do this ?
Thanks in advance
Try this approach instead, using the RowUpdating event:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//Do the check.
//IF check succeeds do nothing
//IF check fails do this:
e.Cancel = true; //Cancels the impending update.
}
If you use the RowUpdating event you can set the Cancel property in the EventArgs object (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewupdateeventargs_members.aspx)
精彩评论