本文介绍了如何从服务器floder gridview的显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到以下错误code
I get error following code
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="img" runat="server" ImageUrl="~/Attachment/<%#Eval("Image") %>" />
</ItemTemplate>
</asp:TemplateField>
错误
分析器错误信息:服务器标签不规范
errorParser Error Message: The server tag is not well formed.
推荐答案
第一次尝试这样的:
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="img" runat="server" ImageUrl="<%# Page.ResolveClientUrl(String.Format("~/Attachment/{0}",Eval("Image"))) %>" />
</ItemTemplate>
</asp:TemplateField>
有另一种选择做服务器不在客户端。如果您需要设置图片网址运行时它是非常有用的。
There is another option to do that in the server not in the client. its is useful if you need to set the image url in run time.
<asp:GridView runat="server" ID="gvActivities" AllowSorting="true" AllowPaging="true"
PageSize="25" AutoGenerateColumns="false" Width="100%" OnSorting="gvActivities_Sorting"
OnRowDataBound="gvActivities_RowDataBound">
<Columns>
<asp:TemplateField HeaderText='Image' HeaderStyle-Width="4%"
SortExpression="ActivityType">
<ItemTemplate>
<asp:Image ID="ImageType" runat="server" AlternateText='<%# Eval("Type") %>' />
</ItemTemplate>
</asp:TemplateField>
有你所看到的,我使用的是OnRowDataBound设置图像的URL。
Has you can see, i am using the OnRowDataBound to set the image url.
- 我不是设置在客户端中IMAGEURL。
- 我检查如果该行类型数据行。
- 然后我创建的图像,并把图像从笑容进去。看到我使用FindControl方法。了将ImageType是在网格中的图像的id
-
然后我设置ImageUrl属性
- I am not setting the ImageURL in the client.
- I am checking if the Row type is a Data Row.
- Then i am creating an image and putting the image from the grin into it. see that i am using the FindControl method. the "ImageType" is the id of the image in the grid.
then i am setting the imageURL Property
protected void gvActivities_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Image img = (Image)e.Row.Cells[0].FindControl("ImageType");
img.ImageUrl = Page.ResolveClientUrl("Image URL path);
img.AlternateText = "Text";
img.ToolTip = "Tooltip";
}
}
这篇关于如何从服务器floder gridview的显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!