GridView: Bind data to template column
-
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 :)
-
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 :)
-
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 :)
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.