LINQ to XML 和 GridView.ImageField

发布于 2024-11-02 13:43:26 字数 548 浏览 8 评论 0原文

我想知道如何根据 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,但不是显示这个,我如何将其更改为图像字段?

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.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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筱果果 2024-11-09 13:43:26

标记:

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

代码隐藏:

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

您的问题是什么?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文