views:

148

answers:

1

I have a gridview which has rows of 'tickets'. A user has the ability to 'claim' a ticket, this is all set up and works. What i need is to be able to change/hide the 'claim' button and replace it with a 'release' or 'open' command button. Can i achieve this at a rowdatabound level? What i do not want is to query the db everytime to see if the ticket is claimed.

A: 

You could cast the button from its Cell, then change its CommandName, and CommandArgs if needed, along with its text; eg use the same actual button for many purposes.

Im asssuming there is some status field that dictates what you can do with a record? Therefore on RowDataBound get this via a datakey, and adjust the button to suit.

Then on its click, check the command name and execute the relevant function / code block?

Edit - like this:

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        Button btn = e.Row.Cells[YourButtonsColumIndex].FindControl("btnYourButtonsID") as Button;
        btn.CommandName = "Release";

        //Or

        ((Button)e.Row.Cells[YourButtonsColumIndex].FindControl("btnYourButtonsID")).CommandName = "Release";
    }

Bearing in mind hidden rows still count in the zero-index column list.

Jammin
Thanks, that worked!
Dooie