This is a migrated thread and some comments may be shown as answers.

[Solved] Display Image or data in cell based on value returned from database

4 Answers 237 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve Napurano
Top achievements
Rank 1
Steve Napurano asked on 06 Oct 2009, 02:21 AM
Hi. I am looking into how to display an image or data in a grid cell based on the value returned from the database.

For instance, if value > 0, display image...if value = 0, display 0

Any insight would be beneficial to me for I am a new member to the Telerik suite.

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Oct 2009, 05:12 AM
Hi Steve,

Try the following approach by placing image control and Label control in GridTemplateColumn of RadGrid and set the visibility of these controls according to the cell value.

ASPX:
 
<telerik:GridTemplateColumn UniqueName="CopyEmail" HeaderText="Copy?"
    <ItemTemplate> 
        <asp:Label ID="Label1" runat="server" Text="0" Visible='<%# (Convert.ToInt32(Eval("Number"))) == 0 ? true : false %>'></asp:Label> 
        <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/Image1.gif" Visible='<%# Convert.ToInt32(Eval("Number")) > 0 ? true : false %>' /> 
    </ItemTemplate> 
    <EditItemTemplate> 
    </EditItemTemplate> 
</telerik:GridTemplateColumn> 

-Shinu.
0
Steve Napurano
Top achievements
Rank 1
answered on 14 Oct 2009, 06:11 PM
Hi, this is giving me a syntax error when I compile..

Visible

 

='<%# Convert.ToInt32(Eval("1")) > 0 ? true : false %>' />

 



I really wanted this but I wanted to try a basic hard coded example (Above)

Visible

 

='<%# Convert.ToInt32(Eval(Container, "DataItem.Unitpack")) > 0 ? true : false %>' />

Getting syntax errors. Any ideas?

Thanks man...

 

0
Accepted
Sebastian
Telerik team
answered on 15 Oct 2009, 01:58 PM
Hello Steve,

In case you develop in VB.NET language, you will need to modify the code slice as follows:

Visible ='<%# IIF(Integer.Parse(Eval(Container, "DataItem.Unitpack")) > 0,  True, False) %>' />

Thus you should eliminate the syntax errors.

Best regards,
Sebastian
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Steve Napurano
Top achievements
Rank 1
answered on 15 Oct 2009, 08:08 PM
Thank you sir...
Tags
Grid
Asked by
Steve Napurano
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Steve Napurano
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or