2011-04-22 4 views
1

xml 문서의 이미지 룰을 기반으로 gridview에 이미지를 추가하는 방법을 알고 싶습니다. 지금까지 내가 ... 엄지 필드에 URL을 보여주기 위해 잘 작동LINQ to XML 및 GridView.ImageField

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

을 가지고 있지만 대신을 보여주는의 내가 어떻게 그 이미지 필드 변경합니까?

+0

GridView 마크 업 보이기 – abatishchev

답변

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

문제는 무엇입니까?

+0

네가 할 수있는 일은 잘하고 있지만 gridview가 이미지를 보여주기를 원합니다. 현재 수행중인 filepatth가 아닙니다. – Kev

+0

@Kev : 이미지의 경로는 어떻게 보이나요? GridView를 포함하는 컨트롤에 상대적이어야합니다. 또는 서버 기준 (예 : '~/Images/foo.gif' – abatishchev

+0

이제 gridview에는 두 개의 열이 있습니다. 하나는 이미지의 URL이고 그 다음에 이미지의 바운드가됩니다. – Kev