Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LINQ到XML和GridView.ImageField_C#_Linq_Gridview_Linq To Xml_Imagefield - Fatal编程技术网

C# LINQ到XML和GridView.ImageField

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

我想知道如何基于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.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();