Assuming you have a regular CommandField within your grid, put the following code anywhere after the grid is loaded (the DataBound event is a good place):
foreach (GridViewRow row in MyGridView.Rows) {
Button deleteButton = (Button)row.Cells(0).Controls(0);
if (statusOnThisRowIsActive) {
deleteButton.Text = "Active";
} else {
deleteButton.Text = "Restore";
}
}
It's important to note that the .Cells(0).Controls(0)
part will need to be manually determined for your grid - it may be the case that your delete button is not the first control in the first cell. As hard-coding the location of the delete button makes this solution fragile, it is actually better to use a regular button within the grid, as you can then use FindControl to get a reference to it and change the text.
In the grid:
<asp:TemplateField>
<asp:Button ID="btnDelete" runat="server" Text="Active" />
</asp:TemplateField>
In the code behind:
foreach (GridViewRow row in MyGridView.Rows) {
Button deleteButton = row.FindControl("btnDelete");
if (row != null && !statusOnThisRowIsActive()) {
deleteButton.Text = "Restore";
}
}