Last post Mar 02, 2015 04:59 AM by sjnaughton
Member
7 Points
29 Posts
Feb 28, 2015 12:37 PM|adilsari|LINK
Does anyone know HOW CAN I display image in ListView.
My pictures are jpg type in a folder?
I tried <% #Eval("imag") %> and <%# Container.DataItem %>' but still not working.
<asp:ListView ID="lVStaffPhotoList" runat="server">
<LayoutTemplate> <ul class="staffPhoto"> <asp:PlaceHolder runat="server" ID="itemContainer" /> </ul> </LayoutTemplate>
<ItemTemplate> <li> <img src='<%# Container.DataItem %>' /> <br /> '<%# Container.DataItem %>' </li> </ItemTemplate>
<EmptyDataTemplate> <div> <p>Sorry - No staff photo found!</p> </div> </EmptyDataTemplate>
</asp:ListView>
private void ShowStaffPictures() {
string[] filesindirectory = Directory.GetFiles(Server.MapPath("~/ETS/staffPhoto"));
List<String> images = new List<string>(filesindirectory.Count());
foreach (string item in filesindirectory) { images.Add(String.Format("~/ETS/staffPhoto/{0}", System.IO.Path.GetFileName(item)));
}
lVStaffPhotoList.DataSource = images; lVStaffPhotoList.DataBind();
// RepeaterImages.DataSource = images; // RepeaterImages.DataBind(); }
Star
9021 Points
2415 Posts
Mar 01, 2015 09:41 AM|Lokesh B R|LINK
Hi,
Create a class with properties and try.
<asp:ListView ID="lVStaffPhotoList" runat="server"> <LayoutTemplate> <ul class="staffPhoto"> <asp:PlaceHolder runat="server" ID="itemContainer" /> </ul> </LayoutTemplate> <ItemTemplate> <li> <img src='<%# Eval("ImagePath") %>' runat="server" /> </li> </ItemTemplate> <EmptyDataTemplate> <div> <p>Sorry - No staff photo found!</p> </div> </EmptyDataTemplate> </asp:ListView> private void ShowStaffPictures() { string[] filesindirectory = Directory.GetFiles(Server.MapPath("~/ETS/staffPhoto")); List<Photo> images = new List<Photo>; foreach (string item in filesindirectory) { images.Add(new Photo() { ImagePath = String.Format("~/ETS/staffPhoto/{0}", System.IO.Path.GetFileName(item)) } ); } lVStaffPhotoList.DataSource = images; lVStaffPhotoList.DataBind(); } public class Photo { public string ImagePath { get; set; }; }
All-Star
52673 Points
15720 Posts
Mar 02, 2015 02:38 AM|oned_gk|LINK
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Container.DataItem.ToString() %>' />
or try add runat="server" to img
<img src='<%# Container.DataItem %>' runat="server" />
40565 Points
6233 Posts
Microsoft
Mar 02, 2015 04:14 AM|Fei Han - MSFT|LINK
Hi adilsari,
Thanks for your post.
You could try to store images url in a DataTable then bind ListView with DataTable.
<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("imgurl") %>' />
DataTable tb = new DataTable(); tb.Columns.Add("imgurl"); foreach (string item in filesindirectory) { string ImagePath = String.Format("~/ETS/staffPhoto/{0}", System.IO.Path.GetFileName(item)); tb.Rows.Add(ImagePath); } lVStaffPhotoList.DataSource = tb; lVStaffPhotoList.DataBind();
Best Regards,
Fei Han
17916 Points
5681 Posts
MVP
Mar 02, 2015 04:59 AM|sjnaughton|LINK
Hi adilsari, you have posted in the Dynamic Data forum is your post regarding Dynamic Data or just general ListView?
Member
7 Points
29 Posts
ListView and Photos
Feb 28, 2015 12:37 PM|adilsari|LINK
Does anyone know HOW CAN I display image in ListView.
My pictures are jpg type in a folder?
I tried <% #Eval("imag") %> and <%# Container.DataItem %>' but still not working.
<asp:ListView ID="lVStaffPhotoList" runat="server">
<LayoutTemplate>
<ul class="staffPhoto">
<asp:PlaceHolder runat="server" ID="itemContainer" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li>
<img src='<%# Container.DataItem %>' />
<br />
'<%# Container.DataItem %>'
</li>
</ItemTemplate>
<EmptyDataTemplate>
<div>
<p>Sorry - No staff photo found!</p>
</div>
</EmptyDataTemplate>
</asp:ListView>
private void ShowStaffPictures()
{
string[] filesindirectory = Directory.GetFiles(Server.MapPath("~/ETS/staffPhoto"));
List<String> images = new List<string>(filesindirectory.Count());
foreach (string item in filesindirectory)
{
images.Add(String.Format("~/ETS/staffPhoto/{0}", System.IO.Path.GetFileName(item)));
}
lVStaffPhotoList.DataSource = images;
lVStaffPhotoList.DataBind();
// RepeaterImages.DataSource = images;
// RepeaterImages.DataBind();
}
Star
9021 Points
2415 Posts
Re: ListView and Photos
Mar 01, 2015 09:41 AM|Lokesh B R|LINK
Hi,
Create a class with properties and try.
All-Star
52673 Points
15720 Posts
Re: ListView and Photos
Mar 02, 2015 02:38 AM|oned_gk|LINK
or try add runat="server" to img
Suwandi - Non Graduate Programmer
All-Star
40565 Points
6233 Posts
Microsoft
Re: ListView and Photos
Mar 02, 2015 04:14 AM|Fei Han - MSFT|LINK
Hi adilsari,
Thanks for your post.
You could try to store images url in a DataTable then bind ListView with DataTable.
Best Regards,
Fei Han
All-Star
17916 Points
5681 Posts
MVP
Re: ListView and Photos
Mar 02, 2015 04:59 AM|sjnaughton|LINK
Hi adilsari, you have posted in the Dynamic Data forum is your post regarding Dynamic Data or just general ListView?
Always seeking an elegant solution.