我正在使用AjaxFileUpload
控件上传多个图像文件。我正在做的是将文件保存到文件夹中,然后将其插入数据库。我的表字段是id
, url
, alt
。我还想为图像输入替代文本,以便它显示为图像的描述。如何在AjaxFileUpload
Control 中编辑它。对于我上传的每张图片,应该会出现一个接受替代文本的文本框。我怎样才能做到这一点。有可能这样做吗??
这是我的aspx代码:
<div id="sliderinsert" style="position:absolute; padding-bottom:5px; background-color:gray; top: 24px; left: 13px;
width: 695px; height: 300px; margin-bottom: 1px; overflow:visible">
<ajaxToolkit:AjaxFileUpload style="position:absolute; width:695px; overflow:auto;max-height:600px" MaximumNumberOfFiles="7" AllowedFileTypes="jpg,jpeg,png,gif"
id="ajaxUpload1" OnUploadComplete="ajaxUpload1_UploadComplete" runat="server" Width="633px"/>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
这是我的代码:
protected void ajaxUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
id+=1;
string filename = Path.GetFileName(e.FileName);
string filepath = Server.MapPath("~/Images/Gallery/" + filename);
ajaxUpload1.SaveAs(filepath);
string Insert = "Insert into slider (slid,slurl) values (@id,@IMAGE_PATH)";
SqlCommand cmd = new SqlCommand(Insert, con);
cmd.Parameters.AddWithValue("@IMAGE_PATH", filepath);
cmd.Parameters.AddWithValue("id", id);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
cmd.Dispose();
}
}