Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. GridView: Bind data to template column

GridView: Bind data to template column

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-netwpfwcf
3 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mail572352
    wrote on last edited by
    #1

    Hi, I have a gridview control on an ASP.NET page which I want to populate by binding an array of items to it. The items were all strings so it was easy to do, just have columns with bound fields and setting the DataFields to the property names like this: I now need to add a new item and it consists of an object with a few strings as properties. I'd like to do this but I can't of course: ...where the Product is the object and Code is a string member. How can I do it? Do I need a template? If so, how? Thanks :)

    K T 2 Replies Last reply
    0
    • M mail572352

      Hi, I have a gridview control on an ASP.NET page which I want to populate by binding an array of items to it. The items were all strings so it was easy to do, just have columns with bound fields and setting the DataFields to the property names like this: I now need to add a new item and it consists of an object with a few strings as properties. I'd like to do this but I can't of course: ...where the Product is the object and Code is a string member. How can I do it? Do I need a template? If so, how? Thanks :)

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      Here is an article I wrote that might be helpful. http://www.codeproject.com/useritems/GridViewObjectDataSource.asp[^] Ben

      1 Reply Last reply
      0
      • M mail572352

        Hi, I have a gridview control on an ASP.NET page which I want to populate by binding an array of items to it. The items were all strings so it was easy to do, just have columns with bound fields and setting the DataFields to the property names like this: I now need to add a new item and it consists of an object with a few strings as properties. I'd like to do this but I can't of course: ...where the Product is the object and Code is a string member. How can I do it? Do I need a template? If so, how? Thanks :)

        T Offline
        T Offline
        thowra
        wrote on last edited by
        #3

        Try this:

        <asp:TemplateField HeaderText="Product Code">
        <ItemTemplate>
        <asp:Label ID="abc" runat="server"
        Text='<%# Eval("Product.Code") %>'>
        </asp:Label>
        </ItemTemplate>
        </asp:TemplateField>

        Evil cannot be conquered in the world... It can only be resisted within oneself.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups