c# - Display photos in dynamic folder asp.net -
i trying design photos manager website application need show of photos in folders base of operations on folder name , utilize 1 aspx page. found many tutorail can work display photos in folder dont know how display photos in folder on take galery, example: have folder photo on host server, in have 2 sub folders are: animal , flower. when click on animal folder, animal photos display on webpage , on when click on flower folder, flowers photos shown.
here code have: aspx page:
<asp:datalist id="datalist1" runat="server" repeatcolumns="5" backcolor="white" bordercolor="#999999" borderstyle="solid" borderwidth="1px" cellpadding="3" forecolor="black" width="100%"> <footerstyle backcolor="#cccccc" /> <selecteditemstyle backcolor="#000099" font-bold="true" forecolor="white" /> <headertemplate> <span class="style2">image gallary</span> </headertemplate> <headerstyle backcolor="black" font-bold="true" forecolor="white" /> <itemtemplate> <asp:imagebutton width="105px" id="image1" runat="server" borderstyle="solid" imageurl='<%# bind("name", "~/[foldername]/{0}") %>' height="94px" /> <br /> <asp:linkbutton id="hyperlink1" text='<%# bind("name") %>' commandargument='<%# bind("name") %>' runat="server" /> </itemtemplate> <footerstyle backcolor="white" forecolor="#333333" /> <itemstyle bordercolor="silver" borderstyle="dotted" borderwidth="1px" horizontalalign="center" verticalalign="bottom" backcolor="white" forecolor="#333333" /> </asp:datalist>
code behind
private void listimages() { directoryinfo dir = new directoryinfo(mappath("~/images")); // it's animal if click on animal , flower when click on flower. fileinfo[] file = dir.getfiles(); arraylist list = new arraylist(); foreach (fileinfo file2 in file) { if (file2.extension == ".jpg" || file2.extension == ".jpeg" || file2.extension == ".gif" || file2.extension == ".png") { list.add(file2); } } datalist1.datasource = list; datalist1.databind(); }
i tried add together list total path as: list.add(dir.tostring()+file2.tostring()) can not phone call aspx page <%# bind("name") %>, error wrong property name! :(
there 2 problem in code:
you need create property class name
property. this:
public class imagetest { public string name {get;set;} }
then in bindlist method:
private void listimages() { directoryinfo dir = new directoryinfo(mappath("~/images/animal")); // it's animal if click on animal , flower when click on flower. fileinfo[] file = dir.getfiles(); // arraylist list = new arraylist(); list<imagetest> list = new list<imagetest>(); foreach (fileinfo file2 in file) { if (file2.extension == ".jpg" || file2.extension == ".jpeg" || file2.extension == ".gif" || file2.extension == ".png") { // list.add(file2); // list.add(dir.tostring() + file2.tostring()); list.add(new test() { name = "http://localhost:58822/images/animal/" + file2.tostring() // localhost path site url }); } } datalist1.datasource = list; datalist1.databind(); }
also need remove ~/[foldername]/{0}") %>' code , maintain simple
imageurl='<%# bind("name") %>'
c# asp.net
No comments:
Post a Comment