Hello, AjaxFileUpload to use it with uploading images to folder and insert the image paht in database,
and I could do this but my problem is that after the file is uploaded the GridView does not refresh to display the uploaded file. I tryied many times to do this but I can't
please help me
this is my code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="fileupload.aspx.cs" Inherits="fileupload" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" AllowedFileTypes="jpg,jpeg,png,gif,pdf"
MaximumNumberOfFiles="10" OnUploadComplete="File_Upload"
Width="500px" />
</div>
<asp:GridView ID="GridView1" runat="server"
style="position: relative; top: 32px; left: 342px">
</asp:GridView>
</form>
</body>
</html>
codebehind code
SqlConnection cn = new SqlConnection("Server= DOCTUS-12\\SQLEXPRESS;Integrated Security=true;Database=testdb");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gridload();
}
}
public void gridload()
{
SqlDataAdapter da = new SqlDataAdapter("select * from fileupload", cn);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
protected void File_Upload(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string filename = e.FileName;
string strDestPath = Server.MapPath("~/Documents/");
string str1 = strDestPath + filename;
AjaxFileUpload1.SaveAs(@strDestPath + filename);
string str = "insert into fileupload(filepath) values('" + str1 + "')";
SqlCommand cmd = new SqlCommand(str, cn);
cn.Open();
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
gridload();
}