Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Datagrid Control (http://www.velocityreviews.com/forums/f60-asp-net-datagrid-control.html)
-   -   multiple data items in each column (http://www.velocityreviews.com/forums/t760458-multiple-data-items-in-each-column.html)

xzzy 04-16-2004 07:30 AM

multiple data items in each column
 
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 04-16-2004 01:06 PM

Re: multiple data items in each column
 
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
>
>


Scott Mitchell [MVP] 04-18-2004 08:59 PM

Re: multiple data items in each column
 
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/de...ebcontrols.asp

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

Happy Programming!

--

Scott Mitchell
mitchell@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

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


All times are GMT. The time now is 09:22 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.