asp:GridView 2 Columns into 1

F

Frenchie

Hi,

I would like to find a way to displys 2 columns into a gridview as 1
column with 2 rows for each row in my database.

The first row would be a short description of the image that is in the
row below.

At the moment I have a column with a picture in it then a second column
next to it with the description.

Here is the code that I use:

<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
AllowPaging="True" CellPadding="2">
<Columns>
<asp:ImageField HeaderText="picture"
DataImageUrlField="URL" DataImageUrlFormatString="{0}">
<ControlStyle Height="240px" Width="352px" />
</asp:ImageField>
<asp:BoundField DataField="Description"
HeaderText="Description" SortExpression="Description" />
</Columns>
</asp:GridView>


Thanks in advance for the help.
 
E

Eliyahu Goldin

You need to use a repeater with an item template containing an html table
with one column and two rows.
 
F

Frenchie

Thank you very much for the post but could you give me a few tip on how
to actually do that? Any examples would be greatly appreciated.


Thanks in advance.
 
F

Frenchie

I have managed to get the repeater and template going by reading some
how too on both of those controls. Now I get the description and the
image on the same column but it's not displaying properly.

First, the description is a gridview and if there are 4 items getting
returned from my query the 4 description are showed first then the 4
images. On top of that, now I have this scenario coming up 4 times on
the same page.

If my query should return 4 descriptions and 4 images, if would like to
see the description then the image then the description then...well you
get it.

Here the code I'm using now...


<asp:Repeater ID="MyRepeater" runat="server"
DataSourceID="SqlDataSource1">
<ItemTemplate >
<tr>
<td >
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
CellPadding="2">
<Columns>
<asp:BoundField DataField="Description"
SortExpression="Description" />

</Columns>
</asp:GridView> </td></tr>
<tr><td >
<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
CellPadding="2">
<Columns>
<asp:ImageField DataImageUrlField="URL"
DataImageUrlFormatString="{0}">
<ControlStyle Height="240px" Width="352px" />
</asp:ImageField>
</Columns>
</asp:GridView > </td>
</tr>
</ItemTemplate>
</asp:Repeater>


 
E

Eliyahu Goldin

You don't need to put any datagrids in the item template. Do just something
like:

<table>
<asp:Repeater ID="MyRepeater" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate >
<tr><td ><%# Eval("Description") %> </td></tr>
<tr><td ><img src='<%# Eval("URL") %>' /></td></tr>
</ItemTemplate>
</asp:Repeater>
</table>
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top