picture in data grid based on value

Discussion in 'ASP .Net' started by Brian Henry, Jul 6, 2004.

  1. Brian Henry

    Brian Henry Guest

    Hello, I am working on a simple email website that is kinda like hotmail...
    but the listing of messages is in a data grid data bound to a table called
    messages... now one of the columns in the messages data table is called read
    if the value is 1 the message is read if 0 then unread... what i want to do
    is show an image in the listing based on that value, if 1 then
    icn-msg-read.gif will be showed in that column for that message row, if 0
    then icn-msg-unread.gif needs to be shown, how would i go about doing this?
    thanks!
     
    Brian Henry, Jul 6, 2004
    #1
    1. Advertising

  2. Dynamically create an image tag, or use an Image Control, and dynamically
    set its URL.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Brian Henry" <> wrote in message
    news:...
    > Hello, I am working on a simple email website that is kinda like

    hotmail...
    > but the listing of messages is in a data grid data bound to a table called
    > messages... now one of the columns in the messages data table is called

    read
    > if the value is 1 the message is read if 0 then unread... what i want to

    do
    > is show an image in the listing based on that value, if 1 then
    > icn-msg-read.gif will be showed in that column for that message row, if 0
    > then icn-msg-unread.gif needs to be shown, how would i go about doing

    this?
    > thanks!
    >
    >
     
    Kevin Spencer, Jul 6, 2004
    #2
    1. Advertising

  3. Brian Henry

    Brian Henry Guest

    yes, I know that but how would i do this in a data bound grid? i need to
    pick which image will be displayed based off the value of the data column...
    right now its just a numeric value read from a data bound column like this
    <%#DataBinder.Eval(Container.DataItem,"Read")%> which ends up showing true
    or false on the data grid because it's a bit value... i wanted to do
    something like <img src='<%=
    ImagePickFunction(DataBinder.Eval(Container.DataItem,"Read"))%> but that of
    course does not work... how would i do this part of the problem? thanks
     
    Brian Henry, Jul 6, 2004
    #3
  4. Hi Brian,

    I think your approach is just correct and you've been very closer to the
    solution. We can just do such task by using a custom helper functdion
    together with the DataBinder.Eval function. But notice that we should
    always put the databinding expression in the <%# %> tag rather than <%=
    %> , they're different, below are some reference on these webform
    expression syntax:

    #Data Binding Expression Syntax
    http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconDatabindingExpres
    sionSyntax.asp?frame=true

    #Web Forms Syntax
    http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconASPPageSyntax.asp
    ?frame=true

    As for your situation, first, we define a helper function in the page class:

    protected string GetImageUrl(object readFlag)
    {
    int iRead = (int)readFlag;
    if(iRead == 0)
    {
    return "Unread.gif";
    }
    else
    {
    return "Read.gif";
    }
    }

    the helper function take an object param because the
    DataBinder.Eval(container, expressioN) will return an object reference. And
    since your datacolumn's value is a number value, we cast it to int and
    return the proper image url depend on its value. After that, we can apply
    it in the page's template together with the DataBinder.Eval expression,
    just as below:

    <img src='<%# GetImageUrl(DataBinder.Eval(Container.DataItem,"ReadColumn"))
    %>'>

    How do you think of this? If you have any other ideas, pleas also feel free
    to post here. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
     
    Steven Cheng[MSFT], Jul 7, 2004
    #4
  5. Brian Henry

    Brian Henry Guest

    Hello,

    That is what I was trying previously, doing it like this

    <img src='<%# GetImageUrl(DataBinder.Eval(Container.DataItem,"ReadColumn"))
    %>'>

    but every time it did, it started poping up with the error with something
    similar to object 'container' can not be found


    "Steven Cheng[MSFT]" <> wrote in message
    news:8vg0$...
    > Hi Brian,
    >
    > I think your approach is just correct and you've been very closer to the
    > solution. We can just do such task by using a custom helper functdion
    > together with the DataBinder.Eval function. But notice that we should
    > always put the databinding expression in the <%# %> tag rather than <%=
    > %> , they're different, below are some reference on these webform
    > expression syntax:
    >
    > #Data Binding Expression Syntax
    >

    http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconDatabindingExpres
    > sionSyntax.asp?frame=true
    >
    > #Web Forms Syntax
    >

    http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconASPPageSyntax.asp
    > ?frame=true
    >
    > As for your situation, first, we define a helper function in the page

    class:
    >
    > protected string GetImageUrl(object readFlag)
    > {
    > int iRead = (int)readFlag;
    > if(iRead == 0)
    > {
    > return "Unread.gif";
    > }
    > else
    > {
    > return "Read.gif";
    > }
    > }
    >
    > the helper function take an object param because the
    > DataBinder.Eval(container, expressioN) will return an object reference.

    And
    > since your datacolumn's value is a number value, we cast it to int and
    > return the proper image url depend on its value. After that, we can apply
    > it in the page's template together with the DataBinder.Eval expression,
    > just as below:
    >
    > <img src='<%#

    GetImageUrl(DataBinder.Eval(Container.DataItem,"ReadColumn"))
    > %>'>
    >
    > How do you think of this? If you have any other ideas, pleas also feel

    free
    > to post here. Thanks.
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    > Get Preview at ASP.NET whidbey
    > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    >
    >
    >
    >
    >
    >
    >
    >
    >
     
    Brian Henry, Jul 7, 2004
    #5
  6. Brian Henry

    Brian Henry Guest

    nevermind, it suddenly works with out changeing any code... odd behavior of
    the code..


    "Brian Henry" <> wrote in message
    news:...
    > Hello,
    >
    > That is what I was trying previously, doing it like this
    >
    > <img src='<%#

    GetImageUrl(DataBinder.Eval(Container.DataItem,"ReadColumn"))
    > %>'>
    >
    > but every time it did, it started poping up with the error with something
    > similar to object 'container' can not be found
    >
    >
    > "Steven Cheng[MSFT]" <> wrote in message
    > news:8vg0$...
    > > Hi Brian,
    > >
    > > I think your approach is just correct and you've been very closer to the
    > > solution. We can just do such task by using a custom helper functdion
    > > together with the DataBinder.Eval function. But notice that we should
    > > always put the databinding expression in the <%# %> tag rather than

    <%=
    > > %> , they're different, below are some reference on these webform
    > > expression syntax:
    > >
    > > #Data Binding Expression Syntax
    > >

    >

    http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconDatabindingExpres
    > > sionSyntax.asp?frame=true
    > >
    > > #Web Forms Syntax
    > >

    >

    http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconASPPageSyntax.asp
    > > ?frame=true
    > >
    > > As for your situation, first, we define a helper function in the page

    > class:
    > >
    > > protected string GetImageUrl(object readFlag)
    > > {
    > > int iRead = (int)readFlag;
    > > if(iRead == 0)
    > > {
    > > return "Unread.gif";
    > > }
    > > else
    > > {
    > > return "Read.gif";
    > > }
    > > }
    > >
    > > the helper function take an object param because the
    > > DataBinder.Eval(container, expressioN) will return an object reference.

    > And
    > > since your datacolumn's value is a number value, we cast it to int and
    > > return the proper image url depend on its value. After that, we can

    apply
    > > it in the page's template together with the DataBinder.Eval expression,
    > > just as below:
    > >
    > > <img src='<%#

    > GetImageUrl(DataBinder.Eval(Container.DataItem,"ReadColumn"))
    > > %>'>
    > >
    > > How do you think of this? If you have any other ideas, pleas also feel

    > free
    > > to post here. Thanks.
    > >
    > > Regards,
    > >
    > > Steven Cheng
    > > Microsoft Online Support
    > >
    > > Get Secure! www.microsoft.com/security
    > > (This posting is provided "AS IS", with no warranties, and confers no
    > > rights.)
    > >
    > > Get Preview at ASP.NET whidbey
    > > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >

    >
    >
     
    Brian Henry, Jul 7, 2004
    #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. =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=

    How to transfer a value from an Invisible Grid to an visible Grid

    =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=, Oct 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    481
    =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=
    Oct 17, 2005
  2. Jive Dadson

    Drawing a grid on a picture

    Jive Dadson, Aug 14, 2006, in forum: Python
    Replies:
    4
    Views:
    352
    Jive Dadson
    Aug 14, 2006
  3. Laphan
    Replies:
    2
    Views:
    113
    Laphan
    Nov 21, 2004
  4. Replies:
    8
    Views:
    1,324
    Mick White
    Apr 19, 2005
Loading...

Share This Page