Search

Saturday, April 25, 2015
0 comments

Nested Gridview example in asp.net c#

6:52 PMSaturday, April 25, 2015
Before we talk about nested gridview asp.net c#. First we talk about gridview control. It is a data source control through which we can bind data in the form of table. In this article, we will take two gridview asp.net controls and we will arrange both control in this way, please see the mentioned picture.

Lets to start how to design it

  1. First to add asp.net gridview in the source page
  2. Add a <Columns> tag inside it.
  3. Add single column inside it using TemplateField with HeaderText property, if you want to add more than one column then add equal number of TemplateField inside it.
  4. Show the data in the browser with the help of ItemTemplate, so add it inside Template Field.
  5. Now, the article's main point is here, Add another gridview asp.net controls inside the ItemTemplate, Now your code look like:
     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
     <Columns>
    <asp:TemplateField HeaderText="Subject Marks">
     <ItemTemplate>
     <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false">
     </asp:GridView>
     </ItemTemplate>
    </asp:TemplateField>
     </Columns>
     </asp:GridView>
  6. Similarly again, repeat the step 2 to 4 for second nested gridview asp.net control. Now, add three columns by using Template Field.
  7. Bind all columns inside the ItemTemplate field of second gridview control, Please see the full code which is mentioned below:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">

<Columns>

<asp:TemplateField HeaderText="Subject Marks">
<ItemTemplate>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Hindi">
<ItemTemplate>
<asp:Label ID="hindilabel" runat="server" Text='<%# Eval("hindi") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Maths">
<ItemTemplate>

<asp:Label ID="mathslabel" runat="server" Text='<%# Eval("maths") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="English">
<ItemTemplate>

<asp:Label ID="englishlabel" runat="server" Text='<%# Eval("English") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top