C# LINQ到XML和GridView.ImageField
我想知道如何基于xml文档中的imageurl向gridview添加图像。到目前为止我已经C# LINQ到XML和GridView.ImageField,c#,linq,gridview,linq-to-xml,imagefield,C#,Linq,Gridview,Linq To Xml,Imagefield,我想知道如何基于xml文档中的imageurl向gridview添加图像。到目前为止我已经 XDocument xmlDoc = XDocument.Load(Server.MapPath("XMLFile.xml")); var q = from c in xmlDoc.Descendants("Images") where c.Element("PropertyId").Value.ToString() == DropDownList1.SelectedValue.ToSt
XDocument xmlDoc = XDocument.Load(Server.MapPath("XMLFile.xml"));
var q = from c in xmlDoc.Descendants("Images")
where c.Element("PropertyId").Value.ToString() == DropDownList1.SelectedValue.ToString()
select new
{
Id = c.Element("PropertyId").Value,
Thumb = c.Element("ThumbUrl").Value
};
GridView1.DataSource = q;
GridView1.DataBind();
在thumb字段中显示url很好,但是如何将其更改为图像字段呢
<asp:GridView runat="server">
<Columns>
<ImageField DataImageUrlField="PhotoPath" />
</Columns>
</<asp:GridView>
你有什么问题?是的,我可以这样做,但我只希望gridview显示图像,而不是当前显示的文件does@Kev:图像的路径看起来如何?它应该相对于包含GridView的控件。或服务器相关,例如,
~/Images/foo.gif
gridview现在有两列。一个是图像的url,另一个是绑定到的图像it@Kev:图像的路径是相对的、绝对的还是什么?
string selectedValue = DropDownList1.SelectedValue.ToString(); // cache it!
var q = from c in xmlDoc.Descendants("Images")
where c.Element("PropertyId").Value.ToString() == selectedValue
select new
{
PhotoPath = c.Element("PhotoPath").Value
};
GridView1.DataSource = q;
GridView1.DataBind();