How to display different type of images in ad rotator in aspx page

2 posts, 0 answers
  1. Farooq
    Farooq avatar
    5 posts
    Member since:
    Nov 2012

    Posted 16 Nov 2012 Link to this post

    I have an Ad Rotator and the File contents are coming from a table column, the problem is sometime the File columns contents are image, sometimes text file or the column is empty. My question is how do I display a static image when there are no attachment images or the attachment is there but it's not an image, its a .txt file or .doc file.

    <telerik:RadRotator ID="rrotAttachmentImages" runat="server"                                                      
      RotatorType="CoverFlowButtons"
    Height="250px" Width="700px"
        ItemHeight="225px" ItemWidth="700px"                                                   
     ScrollDuration="100" >
     <ItemTemplate>
          &nbsp;&nbsp;&nbsp;&nbsp;                                                  
     <asp:CheckBox ID="chkImageDefault" runat="server" 
      Text="Default Image" Visible='<%# Eval("Default").ToString() == "1" %>'></asp:CheckBox>                                                  
     <asp:Label ID="lblImages_Comments" runat="server" Text="Comments:"></asp:Label>
    <telerik:RadTextBox ID="rtxtImageComments" runat="server" Width="300px" Text='<%# Eval("Comments") %>' Enabled="false" ></telerik:RadTextBox>
    <asp:Image runat="server" ID="Image" ImageUrl='<%# Eval("File") %>' AlternateText="Image"></asp:Image>   </ItemTemplate>  </telerik:RadRotator>
    c# code:
     //get file attachments                     
      IQueryable<TableName> IqryAttachments = DAL.GetFileAttachments(recordid, "somepagename");
                        rrotAttachmentImages.DataSource = IqryAttachments;
                        rrotAttachmentImages.DataBind(); 
  2. Farooq
    Farooq avatar
    5 posts
    Member since:
    Nov 2012

    Posted 16 Nov 2012 Link to this post

    solved it using ItemDataBound event:

    Aspx code:

       <telerik:RadRotator ID="rrotAttachmentImages" runat="server"                                                      
      RotatorType="CoverFlowButtons"
    Height="250px" Width="700px"
        ItemHeight="225px" ItemWidth="700px"                                                   
     ScrollDuration="100"
    onitemdatabound="rrotAttachmentImages_ItemDataBound" >
     <ItemTemplate>
          &nbsp;&nbsp;&nbsp;&nbsp;                                                  
     <asp:CheckBox ID="chkImageDefault" runat="server" 
      Text="Default Image" Visible='<%# Eval("Default").ToString() == "1" %>'></asp:CheckBox>                                                  
     <asp:Label ID="lblImages_Comments" runat="server" Text="Comments:"></asp:Label>
    <telerik:RadTextBox ID="rtxtImageComments" runat="server" Width="300px" Text='<%# Eval("Comments") %>' Enabled="false" ></telerik:RadTextBox>
    <asp:Image runat="server" ID="Image" ImageUrl='<%# Eval("File") %>' AlternateText="Image"></asp:Image>   </ItemTemplate>  </telerik:RadRotator>
    C# code:

    protected void rrotAttachmentImages_ItemDataBound(object sender, RadRotatorEventArgs e)
        {
            #region Fixing Document Icon
    
            Image imgImage = e.Item.FindControl("Image") as Image;
            string strFile = imgImage.ImageUrl; 
            bool booImage = false;
    
            if (string.IsNullOrEmpty(strFile))
            {
                imgImage.ImageUrl = "~/somefolder/NoImage.jpg";
            }
            else
            {
                if (strFile.Contains(".jpeg")) booImage = true;
                if (strFile.Contains(".jpg")) booImage = true;
                if (strFile.Contains(".gif")) booImage = true;
                if (strFile.Contains(".bmp")) booImage = true;
                if (strFile.Contains(".png")) booImage = true;
                if (!booImage)
                {
                    if (strFile.EndsWith(".txt") || strFile.EndsWith(".doc")
                        || strFile.EndsWith(".docx")
                        || strFile.EndsWith(".xls") || strFile.EndsWith(".xlsx"))
                    {
                        imgImage.ImageUrl = "~/somefolder/DocumentIco.png";
                    }
                    else
                    {
                        imgImage.ImageUrl = "~/somefolder/NoImage.jpg";
                    }
                }
            }
    
    
            #endregion
        }

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top