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

GridTemplateColumn ItemTemplate Visibility

2 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 09 Jun 2009, 09:55 PM
I have a RadGrid that has one "Comments" TemplateColumn.  I have an image
in the item template that has the tooltip set to the actual "Comments" text.  Since
not all rows have "Comments" in the Sql Table, I was wondering if there is a way
to hide the image if the Text="" or is null.  Possibly something straight in the
image Visible="<% ???????? %>" Any ideas?  Thanks is advance.

Joshua

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 10 Jun 2009, 04:13 AM
Hi Josh,

Try the following code for setting the visibility based on the cell value.

ASPX:
 
<telerik:GridTemplateColumn> 
<ItemTemplate> 
    <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/Image1.gif"  Visible='<%# (DataBinder.Eval(Container.DataItem,"Comments") == "" ) ? false : true %>'/>                         
</ItemTemplate> 
</telerik:GridTemplateColumn> 

Thanks,
Shinu.
0
Josh
Top achievements
Rank 1
answered on 11 Jun 2009, 01:15 PM
The code did not work for me, however, I was able to get it to work with the below code:
ASPX Control  
Visibe='<%# VisibleOrNot(DataBinder.Eval(Container.DataItem, "Comments").ToString())%>'  
Code Behind  
public bool VisibleOrNot(string commentdata)  
{        
    if (commentdata == "")  
        return true;  
    else 
        return false;  

Joshua
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Josh
Top achievements
Rank 1
Share this question
or