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

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

1 Answer 37 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Farooq
Top achievements
Rank 1
Farooq asked on 16 Nov 2012, 08:07 PM
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(); 

1 Answer, 1 is accepted

Sort by
0
Farooq
Top achievements
Rank 1
answered on 16 Nov 2012, 08:48 PM

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
    }

Tags
Rotator
Asked by
Farooq
Top achievements
Rank 1
Answers by
Farooq
Top achievements
Rank 1
Share this question
or