I have a GridView binded to a datasource, i was wondering of how i can check a row cell value (bool) from the database row being bound , and then show a button on the rows where the cell value equals to false..
i am using OndataBound Event to retrieve the Gridview-row being bound, i take the ID show, run another procedure against the database to find the value of the cell from the corresponding Database row.. but i cant figure out how to add the button..
also is there any other ways to handle this scenario?
Solution 1: Create a button with an ID where you want it in the gridview, with an attribute visible=false. Whenever you want to show the button, retrieve it (
currentGridRow.FindControl("chosen button ID")
) and set it's visible attribute to true.put your button in a templatefield, like that:
Solution 2: dynamically create the button (
Button b = new Button; currentGridRow.Cell[].Controls.Add(b);
), but it's a pain to deal with the viewstate and the events handler. Don't go that way.