Display an images in Datagrid

Discussion in 'ASP .Net Web Controls' started by sameer, Dec 1, 2005.

  1. sameer

    sameer Guest

    Hi All,
    heres an easy question which for benig new , i cannot figure it out.

    A datatable pulled from the database which has 10 columns is binded to a
    datagrid and it shows all of them in the datagrid successfully. Now i want to
    add an image next to each record inteh grid, the image is stored on the
    server( not in the dabtase) but the datatable has the path of the image
    (since the path is stored in the database).

    The question is how can i show this image in the datagrid right next to each
    record.
    Woudl be great if someone points to samples.

    thanks
    sameer, Dec 1, 2005
    #1
    1. Advertising

  2. You can add a TemplateColumn with a Image server control defined inside its
    ItemTemplate:

    <asp:TemplateColumn HeaderText="Person Name">
    <ItemTemplate>
    <asp:Image ImageUrl =<%# DataBinder.Eval(Container.DataItem, "ImagePath")%>
    Runat=server ></asp:Image>
    </ItemTemplate>
    </asp:TemplateColumn>

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "sameer" wrote:

    > Hi All,
    > heres an easy question which for benig new , i cannot figure it out.
    >
    > A datatable pulled from the database which has 10 columns is binded to a
    > datagrid and it shows all of them in the datagrid successfully. Now i want to
    > add an image next to each record inteh grid, the image is stored on the
    > server( not in the dabtase) but the datatable has the path of the image
    > (since the path is stored in the database).
    >
    > The question is how can i show this image in the datagrid right next to each
    > record.
    > Woudl be great if someone points to samples.
    >
    > thanks
    >
    Phillip Williams, Dec 1, 2005
    #2
    1. Advertising

  3. sameer

    sameer Guest

    right now i did not set any template for the columns of this grid,i jsut take
    the datatable and bind it to the datagrid. So when i add this template column
    , woudl i have to change any properties like define all the other columns as
    well? or it shold work seemless?

    thanks

    "Phillip Williams" wrote:

    > You can add a TemplateColumn with a Image server control defined inside its
    > ItemTemplate:
    >
    > <asp:TemplateColumn HeaderText="Person Name">
    > <ItemTemplate>
    > <asp:Image ImageUrl =<%# DataBinder.Eval(Container.DataItem, "ImagePath")%>
    > Runat=server ></asp:Image>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "sameer" wrote:
    >
    > > Hi All,
    > > heres an easy question which for benig new , i cannot figure it out.
    > >
    > > A datatable pulled from the database which has 10 columns is binded to a
    > > datagrid and it shows all of them in the datagrid successfully. Now i want to
    > > add an image next to each record inteh grid, the image is stored on the
    > > server( not in the dabtase) but the datatable has the path of the image
    > > (since the path is stored in the database).
    > >
    > > The question is how can i show this image in the datagrid right next to each
    > > record.
    > > Woudl be great if someone points to samples.
    > >
    > > thanks
    > >
    sameer, Dec 1, 2005
    #3
  4. Hi Sameer,

    Explicitly declared template columns appear first followed by the
    Auto-generated columns.

    ---
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "sameer" wrote:

    > right now i did not set any template for the columns of this grid,i jsut take
    > the datatable and bind it to the datagrid. So when i add this template column
    > , woudl i have to change any properties like define all the other columns as
    > well? or it shold work seemless?
    >
    > thanks
    >
    > "Phillip Williams" wrote:
    >
    > > You can add a TemplateColumn with a Image server control defined inside its
    > > ItemTemplate:
    > >
    > > <asp:TemplateColumn HeaderText="Person Name">
    > > <ItemTemplate>
    > > <asp:Image ImageUrl =<%# DataBinder.Eval(Container.DataItem, "ImagePath")%>
    > > Runat=server ></asp:Image>
    > > </ItemTemplate>
    > > </asp:TemplateColumn>
    > >
    > > --
    > > HTH,
    > > Phillip Williams
    > > http://www.societopia.net
    > > http://www.webswapp.com
    > >
    > >
    > > "sameer" wrote:
    > >
    > > > Hi All,
    > > > heres an easy question which for benig new , i cannot figure it out.
    > > >
    > > > A datatable pulled from the database which has 10 columns is binded to a
    > > > datagrid and it shows all of them in the datagrid successfully. Now i want to
    > > > add an image next to each record inteh grid, the image is stored on the
    > > > server( not in the dabtase) but the datatable has the path of the image
    > > > (since the path is stored in the database).
    > > >
    > > > The question is how can i show this image in the datagrid right next to each
    > > > record.
    > > > Woudl be great if someone points to samples.
    > > >
    > > > thanks
    > > >
    Phillip Williams, Dec 2, 2005
    #4
    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. John Do

    Display Images In a datagrid

    John Do, Dec 12, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    3,227
    Pooran Prasad
    Dec 12, 2003
  2. =?Utf-8?B?U3VyZXNo?=
    Replies:
    0
    Views:
    522
    =?Utf-8?B?U3VyZXNo?=
    Mar 2, 2004
  3. Brian K. Williams
    Replies:
    0
    Views:
    543
    Brian K. Williams
    Mar 2, 2004
  4. Alek Davis
    Replies:
    4
    Views:
    7,918
    Alek Davis
    Jun 15, 2004
  5. Nishad

    Display Images in datagrid

    Nishad, Jan 11, 2009, in forum: .NET
    Replies:
    0
    Views:
    468
    Nishad
    Jan 11, 2009
Loading...

Share This Page