首先申明:我才自学ASP.NET一个月。
对很多控件的属性方法都不熟悉。C#语言都是才开始学。
这里遇到的问题我的确很难解决,或许对于各位来说很简单。
说不定有的人几分钟内就能完成。但是希望大家能真的帮帮忙。
网上的确有很多例子,但是我很多没看懂,我现在大胆的接了项目,
没时间去啃书本。只有在能调试的代码中学习。
所以希望各位高手们帮我完善下这段代码。
别发一些技术性文章了。发了我也是收藏。因为现在的确没时间去慢慢啃。
问题并不是很难:
------------------------------------------------------------------------
现在做一个图书上传界面
上传时需取根目录里面的photo文件夹里面的图片的路径。当前页面Default.aspx.一个TEXT1,一个BUTTON1。
当点击BUTTON1时候弹出一个预先固定大小的页面img.aspx
img.aspx预览photo文件夹里面所有的图片。
选择(可选)其中一个图片,img.aspx页面关闭
该TEXT1显示该图片的路径信息。(如:photo/***.jpg)
注:此页面不可刷新。
(因为这个上传仅是页面的一个层而已,刷新后该层是隐藏的)
最终目的:
就是需要一个可行方案用一个TEXT,一个BUTTON弹出页面来搞定读取根目录下photo文件夹内的图片的路径信息。
我就只要这个路径。
img.aspx的代码昨天弄出来了。
但是还要修改。因为这只是图片显示。
并不能选择,更不能把路径当成参数传递。
img.aspx
--------------------------------------------------
前:
 <asp:Repeater  ID="r1"  runat="server">   
<ItemTemplate>            
<asp:Image ID="Image1" runat="server" Height="140px" Width="110px" ImageUrl='<%# Container.DataItem.ToString()%>' 
             style="border-right: silver thin solid; border-top: silver thin solid; border-left: silver thin solid; border-bottom: silver thin solid" />
</ItemTemplate>
</asp:Repeater>
后:
protected void Page_Load(object sender, EventArgs e)
    {
        string web = Request.ApplicationPath;
        string p = Server.MapPath("~/bookpic");
        string[] fs = System.IO.Directory.GetFiles(p);
        string[] f = new String[fs.Length];
        for (int i = 0; i < fs.Length; i++)
        {
            f[i] = web + "/bookpic/" + System.IO.Path.GetFileName(fs[i]);
        }
        r1.DataSource = f;
        r1.DataBind();
    }
(如果我希望图片的下方显示文件名称或者路径应该怎么改?)
-------------------------------------------------------------------------昨天200分没完成。
谁写出全码去跟下就是了。
http://community.csdn.net/Expert/topic/5765/5765283.xml?temp=9.075564E-02
http://community.csdn.net/Expert/topic/5765/5765286.xml?temp=.1385614

解决方案 »

  1.   

    放个FileUpload控件,不更简单么?
      

  2.   

    string imagename = this.FileImage.PostedFile.FileName;//文件名
    string exName = imagename.Substring(imagename.LastIndexOf(".") + 1).ToUpper();//截取后缀名
    string newName = Convert.ToString(DateTime.Now.ToFileTime()) + "." + exName;//新的文件名
    FileImage.PostedFile.SaveAs(Server.MapPath("要保存到的文件夹/" + newName));//保存
      

  3.   

    你也可以控制上传文件的大小
    HttpPostedFile myPostFile = this.Request.Files[0];
    if (myPostFile.ContentLength >= 100000)
    {
        this.Response.Write("<script>alert('文件太大');history.back();</script>");
        this.Response.End();
    }
      

  4.   

    aspx文件:
    <asp:repeater id="r1" runat="server">
    <ItemTemplate>
    <asp:ImageButton ID="Image1" BorderWidth='0px' runat="server" Height="140px" Width="110px" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"Photo")%>' style="border-right: silver thin solid; border-top: silver thin solid; border-left: silver thin solid; border-bottom: silver thin solid" />
    <asp:Label ID="PhotoName" Text='<%# DataBinder.Eval(Container.DataItem,"PhotoName")%>' Runat="server">
    </asp:Label>
    </ItemTemplate>
    </asp:repeater>
    cs文件:
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    string web = Request.ApplicationPath;
    string p = Server.MapPath("~/bookpic"); DataRow myrow;
    DataTable mytab=new DataTable();
    mytab.Columns.Add("Photo",typeof(string));
    mytab.Columns.Add("PhotoName",typeof(string)); string[] fs = System.IO.Directory.GetFiles(p);
    string[] f = new String[fs.Length];
    for (int i = 0; i < fs.Length; i++)
    {
    f[i] = web + "/bookpic/" + System.IO.Path.GetFileName(fs[i]);
    myrow=mytab.NewRow();
    myrow[0]=web + "/bookpic/" + System.IO.Path.GetFileName(fs[i]);
    myrow[1]=System.IO.Path.GetFileName(fs[i]);
    mytab.Rows.Add(myrow);
    mytab.AcceptChanges();
    }
    r1.DataSource = mytab;
    r1.DataBind(); for (int i=0;i<this.r1.Items.Count;i++)
    {
    ((ImageButton)this.r1.Items[i].FindControl("Image1")).Attributes.Add("onclick","alert('"+ mytab.Rows[i]["Photo"].ToString() +"')");
    //((ImageButton)this.r1.Items[i].FindControl("Image1")).Attributes.Add("onclick","opener.window.document.all('要显示图片路径控件的ID').value='"+ mytab.Rows[i]["Photo"].ToString() +"')");//如果要把路径传到父窗口用这条
    } }搞定,LZ可以结贴给分了!
      

  5.   

    传递参数到父窗口的Text框改下(选择以后关闭下):
    //((ImageButton)this.r1.Items[i].FindControl("Image1")).Attributes.Add("onclick","opener.window.document.all('父窗口的Text的ID').value='"+ mytab.Rows[i]["Photo"].ToString() +"');window.close();");//如果要把路径传到父窗口用这条
      

  6.   

    直接运行mg.aspx可以显示图片
    但是运行按钮弹出页面的时候。却都显示不出来?