how to add programmatically a boundfield to a gridview?

Discussion in 'ASP .Net' started by michel, Feb 17, 2007.

  1. michel

    michel Guest

    Hi,

    I want to add programmatically a boundfield to a gridview:

    <asp:GridView ID="GridView1" runat="server">
    <Columns>
    </Columns>
    .....
    </asp:GridView>

    code-behind:
    -----------------
    Dim bf As new BoundField
    GridView1.Controls.Add(bf)

    this gives the error:
    "Value of type 'System.Web.UI.WebControls.BoundField' cannot be converted to
    'System.Web.UI.Control"

    Thanks for help
    Michel
     
    michel, Feb 17, 2007
    #1
    1. Advertisements

  2. michel

    michel Guest

    i found it:

    Dim bf As BoundField
    bf = New BoundField
    bf.DataField = "fld"
    GridView1.Columns.Add(bf)
     
    michel, Feb 17, 2007
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.