Conditional ItemTemplate

3 posts, 1 answers
  1. Paul
    Paul avatar
    16 posts
    Member since:
    Mar 2009

    Posted 29 May 2009 Link to this post

    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. Answer
    Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 29 May 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul
    Paul avatar
    16 posts
    Member since:
    Mar 2009

    Posted 29 May 2009 Link to this post

    Thank You Fiko

    You folks are awesome, great product.
Back to Top