Pradip R.
Pradip R.

Reputation: 450

Require Two Header Row in Grid View

I have a grid view of Cart Items, which was bonded at run-time, Now my requirement for that is i want two header row in Grid as given below in image , How will it be possible ? can anyone help me?

My Design For Grid http://content.screencast.com/users/Pr6546/folders/Default/media/f7da2da4-f80e-4674-b1d4-0ccd872966d2/Capture.PNG http://www.screencast.com/t/g4HkqlSpx

Below is my grid Source

<asp:GridView ID="gvCheckOutItems" GridLines="None" ShowFooter="true" DataKeyNames="Item_No"
    Width="100%" border="0" CellSpacing="0" CellPadding="5" AutoGenerateColumns="false"
    CssClass="Checkout-Grid" runat="server" OnRowCreated="gvCheckOutItems_RowCreated">
    <Columns>
        <asp:TemplateField HeaderStyle-Width="7%">
            <ItemTemplate>
                <asp:LinkButton ID="lnkBtnRemove" runat="server" OnClick="lnkBtnRemove_Click" Text="Remove"
                    CssClass="blue-link"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField HeaderText="Item No" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left"
            DataField="Item_No" HeaderStyle-Width="7%" />
        <asp:BoundField HeaderText="Title" HeaderStyle-HorizontalAlign="Left" FooterStyle-HorizontalAlign="Center"
            ItemStyle-HorizontalAlign="Left" DataField="Title" HeaderStyle-Width="25%" />
        <asp:BoundField HeaderText="Offered By" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left"
            DataField="Trainer" HeaderStyle-Width="16%" FooterText="<strong>Order Total</strong>" />
        <asp:TemplateField>
            <ItemTemplate>
                <asp:TextBox ID="txtItemFormat" runat="server" Text='<%# Eval("Item_Format") %>'
                    Visible="false"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField HeaderText="Format" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left"
            DataField="Format" HeaderStyle-Width="15%" />
        <asp:BoundField HeaderText="Duration" ItemStyle-HorizontalAlign="Right" DataField="Duration"
            HeaderStyle-Width="7%" />
        <asp:TemplateField HeaderStyle-Width="7%" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right"
            FooterStyle-HorizontalAlign="Right" HeaderText="Quantity">
            <ItemTemplate>
                <asp:TextBox ID="txtQuantity" Enabled="false" CssClass="quantity" Text='<%#Eval("Quantity")%>'
                    onblur="fnquantityEmpty(this)" onkeyup="extractNumber(this,0,false);" onkeypress="return blockNonNumbers(this, event, false, false);"
                    runat="server" MaxLength="4" AutoPostBack="true" OnTextChanged="Qty_Changed"></asp:TextBox>
            </ItemTemplate>
            <FooterTemplate>
                <strong>
                    <asp:Label ID="lblFooterQuantity" runat="server"></asp:Label></strong>
            </FooterTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Price" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Center"
            HeaderStyle-Width="7%">
            <ItemTemplate>
                <asp:Label ID="lblPrice" runat="server" Text='<%#getConvertedPrice(Eval("Price")) %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:TextBox ID="txtItemOwnerID" runat="server" Text='<%# Eval("ItemOwnerID") %>'
                    Visible="false"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Subtotal" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right"
            FooterStyle-HorizontalAlign="Right" HeaderStyle-Width="8%">
            <ItemTemplate>
                <asp:Label ID="lblSubTotal" runat="server" Text='<%#getConvertedPrice(Eval("Subtotal")) %>'></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                <strong>
                    <asp:Label ID="lblFooterTotalPrice" runat="server" Text="" ToolTip="Total"></asp:Label></strong>
            </FooterTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Regards

Upvotes: 2

Views: 29543

Answers (4)

the_lotus
the_lotus

Reputation: 12748

An option could be to handle the RowDataBound and on the RowType for Header you set your own RenderMethod and write the HTML yourself.

e.Row.SetRenderMethodDelegate(New RenderMethod(AddressOf RenderHeader))

Upvotes: 1

utsikko
utsikko

Reputation: 1545

Please check the links below. They provide a solution on how to apply multiple rows in GridView. Hopefully, it will get you going.

Upvotes: 0

Ravi Vanapalli
Ravi Vanapalli

Reputation: 9942

Best thing I would suggest is add a row which should be on top of your datasource and for Title & Type/ Format add Offered By & Terms/Schedule as values respectively.

This would generate the desired output for you.

Happy Coding!!!

Upvotes: 1

philwilks
philwilks

Reputation: 669

Have you considered abandoning the gridview and using a repeater control instead? This would give you more flexibility.

Upvotes: 1

Related Questions