我有一个Ad Rotator并且文件内容来自表格列,问题是有时文件列内容是图像,有时文本文件或列是空的。我的问题是如何在没有附件图像或附件存在时显示静态图像,但它不是图像,它是.txt文件或.doc文件。
<telerik:RadRotator ID="rrotAttachmentImages" runat="server"
RotatorType="CoverFlowButtons"
Height="250px" Width="700px"
ItemHeight="225px" ItemWidth="700px"
ScrollDuration="100" >
<ItemTemplate>
<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();
答案 0 :(得分:0)
使用ItemDataBound事件解决了它:
Aspx代码:
<telerik:RadRotator ID="rrotAttachmentImages" runat="server"
RotatorType="CoverFlowButtons"
Height="250px" Width="700px"
ItemHeight="225px" ItemWidth="700px"
ScrollDuration="100"
onitemdatabound="rrotAttachmentImages_ItemDataBound" >
<ItemTemplate>
<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
}