ASP.NET - Gridview Column options - Asked By Naresh Kumar on 06-Sep-10 05:35 AM

Hi all,

Can I have the gridview in the below format.
HeaderColumn1 HeaderColumn2   HeaderColumn3  
Column Column Column
Column | Column Column | Column Column | Column
Row Row Row Row Row


In this I need to have subColumns in a column , can anyone please let me know how to accomplish this.

Thanks in advance.
Anand Malli replied to Naresh Kumar on 06-Sep-10 05:53 AM
Hi Naresh,

You can surely do it with <asp:template> columns,which provides and allows you to take any control inside gridview,so what you can do is under that column you can create html or asp table which will result in the output which you provided

let me know if anything is there
THANKS
Naresh Kumar replied to Anand Malli on 06-Sep-10 06:09 AM
Thanks for your reply,

Can you please send sample gridview with <asp:Template> columns, that would be better.

Anand Malli replied to Naresh Kumar on 06-Sep-10 06:25 AM
HI Naresh,

i have created one sample grid for you..it does not do anything but just to show you how you can create the layout of your choice by using template column,below is mark up for it

<asp:GridView ID="sampleGrid" runat="server" AutoGenerateColumns="True"
    CellPadding="4" ForeColor="#333333" GridLines="None">
    <RowStyle BackColor="#EFF3FB" />
    <Columns>
      <asp:TemplateField HeaderText="HeaderColumn1">
        <ItemTemplate>
          <label></label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="HeaderColumn2">
        <ItemTemplate>
          <table border="1" width="100%">
            <tr>
              <td>
                Col1
              </td>
            </tr>
            <tr>
              <td>
                Col2
              </td>
              <td>
                Col3
              </td>
            </tr>
          </table>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="HeaderColumn3">
        <ItemTemplate>
          <table border="1" width="100%">
            <tr>
              <td>
                Col1
              </td>
              <td>
                Col2
              </td>
               
            </tr>
          </table>
        </ItemTemplate>
      </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <AlternatingRowStyle BackColor="White" />
  </asp:GridView>

now you will write your DataBinder tag inside any of your control where you would like to display the value from db right,but here i am showing how its devided in column and formated..see snapshot


i think this is how you want right...

let me know
thxs
Naresh Kumar replied to Anand Malli on 06-Sep-10 06:58 AM
Thanks a lot for your help.

Have a look at this also,
http://marss.co.ua/MergingGridViewHeaderColumns.aspx