1

xml ドキュメントの imageurl に基づいて、グリッドビューに画像を追加する方法を知りたいです。これまでのところ...

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

マークアップ:

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

あなたの問題は何ですか?

于 2011-04-22T09:32:57.977 に答える