Click here to Skip to main content
15,891,712 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want the columns in my gridview to contain 2 values. It can be done easily in html using template field as shown below.
XML
<asp:GridView ID="GridView1" runat="server">
        <Columns>
        <asp:TemplateField HeaderText="Root">
                    <ItemTemplate>
                        <asp:Table ID="table1" runat="server">
                        <asp:TableRow ID="row1">
                        <asp:TableCell ID="cell1" Text="abc">

                        </asp:TableCell>
                        <asp:TableCell ID="cell2" Text="def">

                        </asp:TableCell>
                        </asp:TableRow>
                        </asp:Table>
                                            </ItemTemplate>
                </asp:TemplateField>
</Columns>
        </asp:GridView>

I want to do this same thing dynamically. Please give me the entire code for the above thing in C# asp.net.
Posted
Updated 1-Feb-14 18:47pm
v2

1 solution

 
Share this answer
 
Comments
Member 9493720 2-Feb-14 1:16am    
the second link solves my problem but what if I want to create template field dynamically?
JoCodes 2-Feb-14 1:25am    
Override InstantiateIn()method of the ITemplate interface.
http://www.mindfiresolutions.com/How-to-add-a-TemplateField-to-a-GridView-dynamically-841.php
http://forums.asp.net/t/1001702.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900