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

Conditional ItemTemplate

2 Answers 154 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 2
Paul asked on 29 May 2009, 07:25 AM
Hi

I have the following code.  It all works except that if the ImageDescription contains a null the page of course fails with an error.  I am using a literal because the ImageDescription may actually have some html in it or just plain text.

Is it possible to preform some conditional logic on the value to either fill the text with a set of spaces or a default description like "No description available" for those records where the ImageDescription is null?

                <telerik:RadRotator ID="RadRotator1" runat="server" DataSourceID="LinqDataSource1" 
                    Height="340px" Width="450px" ItemHeight="340px" ItemWidth="450px" FrameDuration="7000"
                    <ItemTemplate> 
                        <asp:Image ID="Image1" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageURL").ToString().Trim() %>' 
                            Style="height: auto; width: auto" /> 
                    </ItemTemplate> 
                    <ItemTemplate> 
                        <asp:Literal runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ImageDescription").ToString().Trim() %>'></asp:Literal>  
                    </ItemTemplate> 
                </telerik:RadRotator> 
 
 

Thanks Paul

2 Answers, 1 is accepted

Sort by
0
Accepted
Fiko
Telerik team
answered on 29 May 2009, 01:36 PM
Hello Paul,

In such case you do not need to use conditions in your logic. I would suggest to use the following approach:
<telerik:RadRotator ID="RadRotator1" runat="server" DataSourceID="LinqDataSource1" 
    Height="340px" Width="450px" ItemHeight="340px" ItemWidth="450px"
    <ItemTemplate> 
        <asp:Image ID="Image1" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageUrl").ToString().Trim() %>' 
            Style="height: auto; width: auto" /> 
    </ItemTemplate> 
    <ItemTemplate> 
        <asp:Literal ID="Literal1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ImageDescription", "{0}").ToString().Trim() %>'></asp:Literal> 
    </ItemTemplate> 
</telerik:RadRotator> 

I hope this helps.

Greetings,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Paul
Top achievements
Rank 2
answered on 29 May 2009, 10:36 PM
Thank You Fiko

You folks are awesome, great product.
Tags
Rotator
Asked by
Paul
Top achievements
Rank 2
Answers by
Fiko
Telerik team
Paul
Top achievements
Rank 2
Share this question
or