locked
How to split columns in gridview? RRS feed

  • Question

  • User2098296259 posted

    Hi there,

    I am using Visual Studio 2010 where I have a gridview that displays many columns and because of that the user has to scroll horizontally in order to view the rest of the columns.

    Is there a way to split the columns so that each row will contain some columns and some columns underneath them?

    For example, I have 10 columns where each row will show 5 columns with their headers and the other 5 columns below with their headers.

    Your help will be greatly appreciated.

    Friday, October 8, 2010 8:38 PM

Answers

  • User3866881 posted

    Maybe you should use ListView instead of GridView to do this, I don't think columnname can be bound directly.

    <asp:ListView…… ItemPlaceHolder="itmHolder">

             <LayoutTemplate>

                     <table>

                        <tr>

                                   <td>Here Write your 5 columnNames....</td>

                                   ……

                        <tr>

    <tr>

                                   <td>Here Write your 5 columnNames....</td>

                                   ……

                        <tr>

                                <tr runat="itmHolder">

                                </tr>

             </LayoutTemplate>

               <ItemTemplate>

               </ItemTemplate>

    <asp:ListView> 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 11, 2010 10:01 PM

All replies

  • User1224194097 posted

    You can try creating a table in template field

    <asp:GridView ID="Gridview1" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <table>
                        <tr>
                            <td>
                                <%# Eval("Column1"%>
                            </td>
                            <td>
                                <%# Eval("Column2")%>
                            </td>
                            <td>
                                <%# Eval("Column3")%>
                            </td>
                            <td>
                                <%# Eval("Column4")%>
                            </td>
                            <td>
                                <%# Eval("Column5")%>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <%# Eval("Column6"%>
                            </td>
                            <td>
                                <%# Eval("Column7")%>
                            </td>
                            <td>
                                <%# Eval("Column8")%>
                            </td>
                            <td>
                                <%# Eval("Column9")%>
                            </td>
                            <td>
                                <%# Eval("Column10")%>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    Friday, October 8, 2010 9:23 PM
  • User3866881 posted

    Maybe you should use ListView instead of GridView to do this, I don't think columnname can be bound directly.

    <asp:ListView…… ItemPlaceHolder="itmHolder">

             <LayoutTemplate>

                     <table>

                        <tr>

                                   <td>Here Write your 5 columnNames....</td>

                                   ……

                        <tr>

    <tr>

                                   <td>Here Write your 5 columnNames....</td>

                                   ……

                        <tr>

                                <tr runat="itmHolder">

                                </tr>

             </LayoutTemplate>

               <ItemTemplate>

               </ItemTemplate>

    <asp:ListView> 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 11, 2010 10:01 PM