asp:GridView 2 Columns into 1

Discussion in 'ASP .Net Datagrid Control' started by Frenchie, Sep 3, 2006.

  1. Frenchie

    Frenchie Guest

    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.
     
    Frenchie, Sep 3, 2006
    #1
    1. Advertising

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

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    "Frenchie" <> wrote in message
    news:...
    > 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.
    >
     
    Eliyahu Goldin, Sep 3, 2006
    #2
    1. Advertising

  3. Frenchie

    Frenchie Guest

    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.
     
    Frenchie, Sep 3, 2006
    #3
  4. Frenchie

    Frenchie Guest

    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>



    > > Thanks in advance for the help.
     
    Frenchie, Sep 4, 2006
    #4
  5. 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>

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    "Frenchie" <> wrote in message
    news:...
    >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>
    >
    >
    >
    >> > Thanks in advance for the help.

    >
     
    Eliyahu Goldin, Sep 4, 2006
    #5
  6. Frenchie

    Frenchie Guest

    Great! Thanks.
    That is exactly what I was looking for.

    Cheers.
     
    Frenchie, Sep 4, 2006
    #6
    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. helpful sql
    Replies:
    0
    Views:
    817
    helpful sql
    May 19, 2005
  2. Replies:
    5
    Views:
    599
  3. Replies:
    4
    Views:
    941
  4. Jacksm
    Replies:
    2
    Views:
    855
    Paul Chalekian
    Nov 21, 2006
  5. Vinki

    template columns and bound columns in gridview

    Vinki, Apr 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    870
    Vinki
    Apr 25, 2007
Loading...

Share This Page