views:

84

answers:

1

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?

+1  A: 

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:

 <asp:TemplateField HeaderText="foobar" >
    <ItemTemplate>
    <asp:ImageButton ID="plusbutton" CssClass="cplusButton" ToolTip="plusButton" OnClick="buttonAdd_Click" runat="server" Visible = "false"/>
    </ItemTemplate>
</asp:TemplateField>

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.

Vinzz
Solution 1: i cant add a normal button, only ButtonField, and it has no ID property :S.. Solution 2: looks over complicated :D .. i was toying around with properties, can i do sthing like Visible= <% $ some evaluating Expression %> ?
Madi D.
Or should i just switch to A Repeater ?
Madi D.
added sample code
Vinzz