开发者

Hide Gridview Command Buttons

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.开发者_StackOverflow中文版 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜