image in datagrid

Discussion in 'ASP .Net' started by nicholas, Nov 19, 2004.

  1. nicholas

    nicholas Guest

    How can I show or hide an image in a datagrid depending on a field.

    Something like: if myfield <> "" then 'show image' else 'show noimage.gif'
    end if

    the image field contains the image name
    so: 'show image' could be something like <img source="/myfolder<%#
    databinder.eval(....) %>" ..... >

    THX
     
    nicholas, Nov 19, 2004
    #1
    1. Advertising

  2. Override the Item Data Bound event and check the other field in the datagrid
    item event args.

    You could also add a custom field to the dataset you are binding to that
    lists the values for the image and check that on databind.

    HTH

    "nicholas" wrote:

    > How can I show or hide an image in a datagrid depending on a field.
    >
    > Something like: if myfield <> "" then 'show image' else 'show noimage.gif'
    > end if
    >
    > the image field contains the image name
    > so: 'show image' could be something like <img source="/myfolder<%#
    > databinder.eval(....) %>" ..... >
    >
    > THX
    >
    >
    >
     
    =?Utf-8?B?TWlrZUw=?=, Nov 19, 2004
    #2
    1. Advertising

  3. nicholas

    nicholas Guest

    Could you explain your first proposition, I don't realy understand what you
    mean.

    THX a lot,
    Nic

    "MikeL" <> wrote in message
    news:...
    > Override the Item Data Bound event and check the other field in the

    datagrid
    > item event args.
    >
    > You could also add a custom field to the dataset you are binding to that
    > lists the values for the image and check that on databind.
    >
    > HTH
    >
    > "nicholas" wrote:
    >
    > > How can I show or hide an image in a datagrid depending on a field.
    > >
    > > Something like: if myfield <> "" then 'show image' else 'show

    noimage.gif'
    > > end if
    > >
    > > the image field contains the image name
    > > so: 'show image' could be something like <img source="/myfolder<%#
    > > databinder.eval(....) %>" ..... >
    > >
    > > THX
    > >
    > >
    > >
     
    nicholas, Nov 19, 2004
    #3
  4. When you bind a dataset to a datagrid an event happens for every row that is
    binded. Therefore you need to override that event and check your field(s).
    Here is an article on doing this:

    http://www.csharphelp.com/archives3/archive570.html

    Here is another article on how to highlight a row in a datagrid. Just
    switch the example to what you need to do.

    http://www.dotnetjunkies.com/HowTo/CD157079-5F60-4031-8BFB-9F8C7478D586.dcik

    HTH

    MikeL

    "nicholas" wrote:

    > Could you explain your first proposition, I don't realy understand what you
    > mean.
    >
    > THX a lot,
    > Nic
    >
    > "MikeL" <> wrote in message
    > news:...
    > > Override the Item Data Bound event and check the other field in the

    > datagrid
    > > item event args.
    > >
    > > You could also add a custom field to the dataset you are binding to that
    > > lists the values for the image and check that on databind.
    > >
    > > HTH
    > >
    > > "nicholas" wrote:
    > >
    > > > How can I show or hide an image in a datagrid depending on a field.
    > > >
    > > > Something like: if myfield <> "" then 'show image' else 'show

    > noimage.gif'
    > > > end if
    > > >
    > > > the image field contains the image name
    > > > so: 'show image' could be something like <img source="/myfolder<%#
    > > > databinder.eval(....) %>" ..... >
    > > >
    > > > THX
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?TWlrZUw=?=, Nov 19, 2004
    #4
  5. The easiest way that I've found of doing it is by setting an event
    handler on the ItemDataBound event. Put a placeholder control into
    your item template, pull it out on the data bound event, then do:

    if (whatever)
    plcHolder.Controls.Add("<img src=\"whatever.jpg\" />");

    or you could even extend that concept and use an HtmlImage control
    (<img runat="server" />) instead of a placeholder ... in fact, that
    would be a little nicer.

    Hope that helps,
    Joel Martinez
    http://www.onetug.org - Orlando .NET User Group
    http://www.codecube.net - blog

    "nicholas" <> wrote in message news:<>...
    > How can I show or hide an image in a datagrid depending on a field.
    >
    > Something like: if myfield <> "" then 'show image' else 'show noimage.gif'
    > end if
    >
    > the image field contains the image name
    > so: 'show image' could be something like <img source="/myfolder<%#
    > databinder.eval(....) %>" ..... >
    >
    > THX
     
    Joel Martinez, Nov 19, 2004
    #5
    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. Jerry J
    Replies:
    0
    Views:
    570
    Jerry J
    Jul 18, 2003
  2. Mike John
    Replies:
    0
    Views:
    538
    Mike John
    Jul 28, 2003
  3. Gary B

    Image can't hold an image?

    Gary B, Jul 31, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    365
    Steve C. Orr, MCSD
    Aug 1, 2003
  4. Laszlo Zsolt Nagy
    Replies:
    1
    Views:
    1,433
    Kartic
    Jan 26, 2005
  5. Andreas Klemt
    Replies:
    0
    Views:
    334
    Andreas Klemt
    Oct 8, 2003
Loading...

Share This Page