Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > image in datagrid

Reply
Thread Tools

image in datagrid

 
 
nicholas
Guest
Posts: n/a
 
      11-19-2004
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZUw=?=
Guest
Posts: n/a
 
      11-19-2004
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
>
>
>

 
Reply With Quote
 
 
 
 
nicholas
Guest
Posts: n/a
 
      11-19-2004
Could you explain your first proposition, I don't realy understand what you
mean.

THX a lot,
Nic

"MikeL" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?TWlrZUw=?=
Guest
Posts: n/a
 
      11-19-2004
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/C...C7478D586.dcik

HTH

MikeL

"nicholas" wrote:

> Could you explain your first proposition, I don't realy understand what you
> mean.
>
> THX a lot,
> Nic
>
> "MikeL" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
Joel Martinez
Guest
Posts: n/a
 
      11-19-2004
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" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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

 
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
wx.Image: Couldn't add an image to the image list. Laszlo Zsolt Nagy Python 1 01-26-2005 09:55 PM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM
Image can't hold an image? Gary B ASP .Net 3 08-01-2003 01:31 AM
How To Browse for an image file and save it to image server folder Mike John ASP .Net 0 07-28-2003 04:55 PM
Streaming Image data to an image viewer Jerry J ASP .Net 0 07-18-2003 01:33 PM



Advertisments