views:

33

answers:

2

Hello,

I have grid which displays users information. I have commandColumn with edit, delete commands. Delete means change users status to archive. What I want is to have delete button in rows with users with status active and restore button (it may be only change in text) in rows with users with status archive.

How can I achive such fuctionality ?

+1  A: 

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";
    }
}
Jason Berkan
+1  A: 

Hi,

Such tasks are possible to implement using the ASPxGridView's CommandButtonInitialize event. An example of using this event is available at:

http://community.devexpress.com/blogs/aspnet/archive/2009/01/13/how-to-disable-command-buttons-in-aspxgridview.aspx

This event is described in our documentation at: http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_CommandButtonInitializetopic

DevExpress Team