在数据库中上传图像url并在没有网格视图的情况下进行检索 [英] upload images url in database and retrive it without grid view

查看:56
本文介绍了在数据库中上传图像url并在没有网格视图的情况下进行检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在数据库中保存图像路径并检索没有网格视图的图像

i want to save image path in database and retrive that images without grid view

推荐答案


可以进行上传使用FileUpload控件...
为postedFile赋予一个唯一的名称(也许您可以在上载时间之前添加前缀)并将其保存在磁盘上,然后将FilePath插入新行中


可以使用中继器代替GridView,在其中可以自己定义其外观...
Upload can be made with the FileUpload Control...
Give the postedFile a unique name (mabe you can prefix the uploadtime) and save it on disk, then insert FilePath into new row


Instead of GridView you could take a repeater in which you can define its appearance by yourself...
<asp:Repeater runat="server" ID="repImageGallery">
    <ItemTemplate>
        <asp:Image runat="server" ID="img" ImageUrl='<%#Eval("ImageUrl") %>' />
    </ItemTemplate>
</asp:Repeater>



CodeBehind:



CodeBehind:

repImageGallery.DataSource =  DB.GetImageNames();
repImageGallery.DataBind();




Markus




Markus


尝试使用此方法上传!

try this method to upload!

protected void btnSub_Click(object sender, EventArgs e)
    {
        try
        {
            string filename = FileUpload1.FileName;
            FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\UploadChairoChart\\" + filename));
            string path = "~\\UploadChairoChart\\" + filename;
            SqlConnection con = new SqlConnection(str);
            lblinfo.Text = "";
            lblinfo.Text += " Uploaded Successfully ";
            cmd = new SqlCommand("Insert into tblChart(headline,url) values(@headline,'" + path + "')", con);
            cmd.Parameters.AddWithValue("headline", TextBox5.Text);

            cmd.CommandType = CommandType.Text;
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            uploadDirectory = Path.Combine(Request.PhysicalApplicationPath, "UploadChairoChart");
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }


并按照MZwahlen的建议使用Repeater


and to retrive use Repeater as MZwahlen suggested


这篇关于在数据库中上传图像url并在没有网格视图的情况下进行检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆