2 rows for each database record in a gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • captainB
    New Member
    • Aug 2009
    • 23

    2 rows for each database record in a gridview

    hi and thanks for reading.
    I am working on a web page that will display records from a database. Each record has a total of 8 columns. One column may be as long as 500 characters, and the other 7 columns are between 5 to 25 characters. For each record in the dataset returned from the database, the short columns should be above, and the long column below.

    In other words, each database record is made of two rows, the 7 short fields in the top row (each field in a cell), and the long field in the bottom row in one cell.

    Both rows should be similar in length.

    How would I go about doing this?

    Thanks!
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Database How-to parts 1 and 2
    Database tutorial Part 1
    Database tutorial Part 2

    Comment

    • semomaniz
      Recognized Expert New Member
      • Oct 2007
      • 210

      #3
      You can use a Repeater Control to achieve this. Just design a table inside the repeater as template and then bind the data to the repeater control

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Or you could use a GridView control which will generate an HTML table for you based on a Data Source (which is the data you retrieve from the database). The GridView control gives you built in paging capability and many other features. It is very flexible and customizable and it is typically used to display and manage data that is retrieve from a database.

        Now, to get 2 rows for each record you need to use a TemplateField. A TemplateField lets you specify how the data that the GridView is bound to is going to be displayed for a particular column. Turn off AutoGenerateCol umns if you are using this or else you will see duplicate data appearing.

        For example:
        Code:
        <asp:GridView ID="myGridView" runat="server" AutoGenerateColumns="False">
          <Columns>
            <asp:TemplateField>
              <ItemTemplate>
                <table border="0">
                  <tr>
                    <td><%#Eval("FirstName") %></td>
                    <td><%#Eval("LastName") %></td>
                  </tr>
                  <tr>
                    <td><%#Eval("Information") %></td>
                  </tr>
                </table>
              </ItemTemplate>
            </asp:TemplateField>
           <asp:BoundField DataField="info2" />
           <asp:BoundField DataField="info3" />
          </Columns>
        </asp:GridView>


        -Frinny

        Comment

        • captainB
          New Member
          • Aug 2009
          • 23

          #5
          Thank you Frinny for your reply. I ended up using a repeater like semomaniz suggested.

          And then my boss wanted to use Ubuntu, Apache and PHP - so it looks like I'm back to page one.

          cheers!

          Comment

          Working...