我使用AjaxFileUpload
控件上传多个图片文件。我正在做的是将文件保存到一个文件夹,然后将其插入数据库。我的表格字段为id
,url
,alt
。我还想为图像输入Alternate Text,以便它显示为图像的描述。如何在AjaxFileUpload
控件中对其进行编辑。对于每个图像,我上传一个文本框以接受应该出现的替换文本。我怎样才能做到这一点。是否有可能这样做。??
这是我的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();
}
}