0

我有一个广告旋转器,文件内容来自表格列,问题是有时文件列内容是图像,有时是文本文件或列是空的。我的问题是,当没有附件图像或附件存在但它不是图像,它是 .txt 文件或 .doc 文件时,如何显示静态图像。

<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#代码:

    //get file attachments                     
  IQueryable<TableName> IqryAttachments = DAL.GetFileAttachments(recordid, "somepagename");
                    rrotAttachmentImages.DataSource = IqryAttachments;
                    rrotAttachmentImages.DataBind(); 
4

1 回答 1

0

使用 ItemDataBound 事件解决了它:

ASP代码:

    <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>

ItemDataBound 事件的 C# 代码:

 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.ToLower().EndsWith(".jpeg")) booImage = true;
                if (strFile.ToLower().EndsWith(".jpg")) booImage = true;
                if (strFile.ToLower().EndsWith(".gif")) booImage = true;
                if (strFile.ToLower().EndsWith(".bmp")) booImage = true;
                if (strFile.ToLower().EndsWith(".png")) booImage = true;
                if (!booImage)
                {
                    if (strFile.ToLower().EndsWith(".txt") || strFile.ToLower().EndsWith(".doc")
                        || strFile.ToLower().EndsWith(".docx")
                        || strFile.ToLower().EndsWith(".xls") || strFile.ToLower().EndsWith(".xlsx"))
                    {
                        imgImage.ImageUrl = "~/somefolder/DocumentIco.png";
                    }
                    else
                    {
                        imgImage.ImageUrl = "~/somefolder/NoImage.jpg";
                    }
                }
        }


        #endregion
    }
于 2012-11-16T20:46:03.223 回答