LINQ to XML and GridView.ImageField
i am wanting to know how to add an image to a gridview based on the imageurl in a xml document. so far i have...
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开发者_如何学JAVA.Element("ThumbUrl").Value
};
GridView1.DataSource = q;
GridView1.DataBind();
which works fine to show the url in the thumb field but instead of showing this how do i change it an image field?
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?
精彩评论