1

我想知道如何根据 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();

可以很好地在拇指字段中显示 url,但不是显示这个,我如何将其更改为图像字段?

4

1 回答 1

0

Markup:

<asp:GridView runat="server">
    <Columns>
        <ImageField DataImageUrlField="PhotoPath" />
    </Columns>
</<asp:GridView>

Code-behind:

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();

What is your problem?

于 2011-04-22T09:32:57.977 回答