GridView Edit 和Delete
前台:
<asp:CommandField ButtonType="Image" HeaderText="Edit" EditImageUrl="~/client_support/images/edit.GIF" UpdateImageUrl ="~/client_support/images/save.gif" CancelImageUrl="~/client_support/images/cancel.gif" ShowEditButton ="True" >
</asp:CommandField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:ImageButton ID = "ibnDelete" runat="server" ImageUrl ="~/client_support/images/del.gif" CommandName="Delete"
OnClientClick ="return confirm('Are you sure to delete?');"/>
</ItemTemplate>
</asp:TemplateField>
后台:
protected void gdvTax_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
this.gdvTax.EditIndex = e.NewEditIndex;
BindGridView();
}
catch (Exception ex)
{
AlertExceptionMessage(ex, MethodBase.GetCurrentMethod());
}
}
protected void gdvTax_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
//Update
AlertMessage("Update success!");
this.gdvTax.EditIndex = -1;
BindGridView();
}
catch (Exception ex)
{
AlertExceptionMessage(ex, MethodBase.GetCurrentMethod());
}
}
protected void gdvTax_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
try
{
this.gdvTax.EditIndex = -1;
BindGridView();
}
catch (Exception ex)
{
AlertExceptionMessage(ex, MethodBase.GetCurrentMethod());
}
}
protected void gdvTax_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
//Delete
AlertMessage("Delete success!");
BindGridView();
}
catch (Exception ex)
{
AlertExceptionMessage(ex, MethodBase.GetCurrentMethod());
}
}