Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > multiple data items in each column

Reply
Thread Tools

multiple data items in each column

 
 
xzzy
Guest
Posts: n/a
 
      04-16-2004
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


 
Reply With Quote
 
 
 
 
Zach Wells
Guest
Posts: n/a
 
      04-16-2004
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
>
>

 
Reply With Quote
 
 
 
 
Scott Mitchell [MVP]
Guest
Posts: n/a
 
      04-18-2004
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView default column too small for description column from data JB ASP .Net 1 09-21-2009 03:04 PM
resolve single line with multiple items into mutliple lines, single items ela Perl Misc 12 04-06-2009 06:47 PM
1 Gridview. Dropdown A is column from database, Dropdown B is column from database, Data in A and B must be from same row. anonymoushamster@gmail.com ASP .Net 2 11-07-2007 12:40 PM
Multiple ISPs and Multiple IP Ranges from Each ISP Chennak Cisco 10 06-08-2005 09:29 PM
Activa or not activate a button column depending if another data column has data or not carlos perez ASP .Net 0 06-08-2004 02:16 PM



Advertisments