Binding a Button to a GridView

Posted by Tyler on Stack Overflow See other posts from Stack Overflow or by Tyler
Published on 2011-01-07T20:49:10Z Indexed on 2011/01/07 20:54 UTC
Read the original article Hit count: 265

Filed under:
|
|
|

This a pretty simple question, I'm just not sure how to do it exactly. I would like to bind a Button or perhaps ImageButton to a GridView in ASP.NET/C#. Currently, the GridView has two columns and is bound to a DataTable with two columns. I want to add a third column to the GridView, which will include the Button.

I know GridView has ButtonField, but I'm not too sure how to go about using it to do what I want. I want to dynamically generate these Buttons and add them to the GridView.

Here is how my GridView looks right now:

<asp:GridView 
    ID="GridView1"
    Runat="server">
    <Columns>
        <asp:HyperLinkField 
            HeaderText="Display Name"
            DataNavigateUrlFields="DISPNAME"
            DataNavigateUrlFormatString="ViewItem.aspx"
            DataTextField="DISPNAME">
            <ItemStyle Width="70%" />
        </asp:HyperLinkField>
        <asp:BoundField
            DataField="TypeDisp"
            HeaderText="Type">
            <ItemStyle Width="20%" />
        </asp:BoundField>
    </Columns>
 </asp:GridView>

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET