How to add a button control dynamically into a GridView cell ? VB.NET

Look, it´s simple. I have a GridView which is populated with data from my database.

What I want is put a button in each cell that contains a specific datum.

Pls, look the image below. It describes exactly what I want

In VB.NET, pls! =)

Example Image

Thanks very much!


ANSWERS:


You are going to need to define the button control inside of the <Columns> section of your GridView markup, like this:

<asp:gridview id="CustomersGridView" runat="server">
    <columns>
        <asp:boundfield datafield="DateColumn" headertext="Date"/>
        <asp:TemplateField>
            <HeaderTemplate>
                Positive
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label id="LabelPositive" runat="server" Text='<%# Eval("PositiveColumn")%>' />
                <br />
                <asp:Button id="ButtonPositive" runat="server" Text="Show" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <HeaderTemplate>
                Negative
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label id="LabelNegative" runat="server" Text='<%# Eval("NegativeColumn")%>' />
                <br />
                <asp:Button id="ButtonNegative" runat="server" Text="Show" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <HeaderTemplate>
                Neutral
            </HeaderTemplate>
            <ItemTemplate>
                <asp:Label id="LabelNeutral" runat="server" Text='<%# Eval("NeutralColumn")%>' />
                <br />
                <asp:Button id="ButtonNeutral" runat="server" Text="Show" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:boundfield datafield="NoCommentsColumn" headertext="No Comments"/>
        <asp:boundfield datafield="TotalColumn" headertext="Total"/>
    </columns>
</asp:gridview>

Note: The datafield and Eval() calls are bound to made up names like NeutralColumn and NoCommentsColumn, substitute those names with your real database field names.


You need to add while data binding the grid. Look for an event call and handle your code there.



 MORE:


 ? Dynamically added button click event fire only once
 ? Dynamic Button Click in Table
 ? Create onClick event for dynamically created button asp.net
 ? Dynamically Add Click event to asp button
 ? Dynamically Add Click event to asp button
 ? Dynamically Add Click event to asp button
 ? Button Click Event Getting Lost
 ? Dynamically assign button events in c# asp.net
 ? how to create an asp button dynamically and add event to it
 ? C# how to handle multiple button click events?