I have a GridView control and I have enabled editing.
My edit & update buttons are both LinkButtons, as below:
<asp:LinkButton ID="buttonEdit" runat="server" Text="Edit" CausesValidation="false"
CommandName="Edit" />
<asp:LinkButton ID="buttonUpdate" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" ValidationGroup="Edit" />
When the user click the edit button one of the columns has a textbox which allows the record to be edited:
<EditItemTemplate>
<asp:TextBox ID="textBoxEdit" runat="server" Text='<%#Eval("Name") %>' />
<asp:Label ID="labelEditWarning" CssClass="error" runat="server" Text="Name already exists" Visible="false" />
</EditItemTemplate>
When the user clicks the Update link button the grid's RowCommand Event fires. Within here I want to perform validation against existing records in the database. If validation fails I then what to stop the grid's RowUpdating event firing but there seems no way to do this!?
protected void gridName_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Edit"))
{
//Perform validation & cancel update if the validation fails.
}
}
protected void gridName_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//Update my record. But I don't want this to fire if my validation fails in
//the row command event.
}
Can anyone help?
I'm using ASP.Net 4.0
Thanks in advance.