multiple data items in each column

Discussion in 'ASP .Net Datagrid Control' started by xzzy, Apr 16, 2004.

  1. xzzy

    xzzy Guest

    How can I display more than one field in a column of a datagrid?

    i.e. doing this with old asp and looping thru a recordset it would be
    something like:

    <table>
    do while not eof
    <tr>
    <td>ABC</td>
    <td>DEF</td>
    </tr>
    <tr>
    <td>GHI</td>
    <td>JKL</td>
    </tr>
    read next
    loop
    </table>

    Thank you
     
    xzzy, Apr 16, 2004
    #1
    1. Advertising

  2. xzzy

    Zach Wells Guest

    I've never done it but I'd suspect that you could use an item template
    column and then just put the following code in there:

    <ItemTemplate>
    <asp:Label id=Label1
    runat="server"
    Text='<%# DataBinder.Eval(Container.DataItem, "FieldName1") %>'>
    </asp:Label>
    <asp:Label id=Label1
    runat="server"
    Text='<%# DataBinder.Eval(Container.DataItem, "FieldName2") %>'>
    </asp:Label>
    </ItemTemplate>


    Zach

    xzzy wrote:
    > How can I display more than one field in a column of a datagrid?
    >
    > i.e. doing this with old asp and looping thru a recordset it would be
    > something like:
    >
    > <table>
    > do while not eof
    > <tr>
    > <td>ABC</td>
    > <td>DEF</td>
    > </tr>
    > <tr>
    > <td>GHI</td>
    > <td>JKL</td>
    > </tr>
    > read next
    > loop
    > </table>
    >
    > Thank you
    >
    >
     
    Zach Wells, Apr 16, 2004
    #2
    1. Advertising

  3. Zach Wells wrote:
    >> How can I display more than one field in a column of a datagrid?

    >
    > I've never done it but I'd suspect that you could use an item template
    > column and then just put the following code in there:
    >
    > <ItemTemplate>
    > <asp:Label id=Label1
    > runat="server"
    > Text='<%# DataBinder.Eval(Container.DataItem, "FieldName1") %>'>
    > </asp:Label>
    > <asp:Label id=Label1
    > runat="server"
    > Text='<%# DataBinder.Eval(Container.DataItem, "FieldName2") %>'>
    > </asp:Label>
    > </ItemTemplate>


    While this will definitely display two records in one table row, it will
    not generate the HTML the original poster was interested in. Namely, it
    won't necessarily have the second Label's value line up in each row, as
    it would with the desired HTML provided originally.

    To get the HTML rendered as specified in the original post, one would
    need to use a DataList with RepeatColumns set to 2, or a Repeater,
    generating the apporpriate HTML markup.

    To learn more about the three Data Web controls check out:

    Deciding When to Use the DataGrid, DataList, or Repeater
    http://msdn.microsoft.com/library/d...dnaspp/html/aspnet-whenusedatawebcontrols.asp

    Or check out my book, ASP.NET Data Web Controls Kick Start
    [http://www.amazon.com/exec/obidos/ASIN/0672325012/4guysfromrollaco]

    Happy Programming!

    --

    Scott Mitchell

    http://www.4GuysFromRolla.com
    http://www.ASPFAQs.com
    http://www.ASPMessageboard.com

    * When you think ASP, think 4GuysFromRolla.com!
     
    Scott Mitchell [MVP], Apr 18, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. carlos perez
    Replies:
    0
    Views:
    420
    carlos perez
    Jun 8, 2004
  2. John Blair
    Replies:
    1
    Views:
    412
    Eliyahu Goldin
    Aug 3, 2005
  3. Tjerk Wolterink

    xsl:for-each for each 3 elements problem

    Tjerk Wolterink, Nov 3, 2004, in forum: XML
    Replies:
    3
    Views:
    432
    Tjerk Wolterink
    Nov 3, 2004
  4. Pat Maddox
    Replies:
    6
    Views:
    158
    Marcin Mielżyński
    Jan 20, 2006
  5. ela
    Replies:
    12
    Views:
    356
    Uri Guttman
    Apr 6, 2009
Loading...

Share This Page