multiple data items in each column

X

xzzy

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
 
Z

Zach Wells

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
 
S

Scott Mitchell [MVP]

Zach said:
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
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top