2013-10-21 47 views

回答

0

不知道你到底如何是動態路徑等看起來像,但你可以嘗試這樣的

代碼隱藏

string dynamicPath = "~/dynamicimages/"; 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     DirectoryInfo dir = new DirectoryInfo(Server.MapPath(dynamicPath)); 
     FileInfo[] dirInfos = dir.GetFiles(); 

     Repeater1.DataSource = dirInfos; 
     Repeater1.DataBind(); 
    } 

    protected string GetImageURL(object fileName) 
    { 
     return dynamicPath + fileName.ToString(); 
    } 

.aspx文件的東西

<asp:Repeater ID="Repeater1" runat="server"> 
    <ItemTemplate> 
     <asp:Image ID="Image1" runat="server" ImageUrl='<%# GetImageURL(Eval("Name")) %>' /> 
</ItemTemplate> 
</asp:Repeater>