Update gridview with fileupload
how Update gridview with fileupload
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
hothorasman panjaitanPosted Feb 9, 2015, 12:09 PM
this my code
if I update fileupload1 then the fileupload2 changed / deleted
protected void Updatedata(object sender, GridViewUpdateEventArgs e)
{
MySqlConnection con = new MySqlConnection(strConnString);
string id_peraturan = GridView1.DataKeys[e.RowIndex].Value.ToString();
FileUpload FileUpload1 = (FileUpload)GridView1.Rows[e.RowIndex].FindControl("FileUpload1") as FileUpload;
FileUpload FileUpload2 = (FileUpload)GridView1.Rows[e.RowIndex].FindControl("FileUpload2") as FileUpload;
FileUpload FileUpload3 = (FileUpload)GridView1.Rows[e.RowIndex].FindControl("FileUpload3") as FileUpload;
string fileName1 = string.Empty;
string fileName2 = string.Empty;
string fileName3 = string.Empty;
string perda1 = ("Pembentukan/"); //fle Pembentukan
string perda2 = ("Pengelolaan/"); //file pengelolaan
string perda3 = ("Retribusi/"); //file retribusi
if (FileUpload1.HasFile)
fileName1 = Path.GetFileName(FileUpload1.FileName);
if (FileUpload2.HasFile)
fileName2 = Path.GetFileName(FileUpload2.FileName);
if (FileUpload3.HasFile)
fileName3 = Path.GetFileName(FileUpload3.FileName);
if (FileUpload1.HasFile)
{
perda1 += FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("Pembentukan/") + fileName1);
}
if (FileUpload2.HasFile)
{
perda2 += FileUpload2.FileName;
FileUpload2.PostedFile.SaveAs(Server.MapPath(perda2));
}
if (FileUpload3.HasFile)
{
perda3 += FileUpload3.FileName;
FileUpload3.PostedFile.SaveAs(Server.MapPath(perda3));
}
con.Open();
MySqlCommand update = new MySqlCommand("UPDATE tbl_peraturan SET namafile1='" + fileName1 + "',perda_pembentukan='" + perda1 + "',fileName1='" + fileName2 + "',perda_pengelolaan='" + perda2 + "',fileName3='"+fileName3+"',perda_retribusi='" + perda3 + "' WHERE ID_PERATURAN=" + id_peraturan + " ", con);
update.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
tampilgird();
}
hothorasman panjaitanPosted Feb 9, 2015, 5:16 AM
this my code
if I update fileupload1 then the fileupload2 changed / deleted
protected void Updatedata(object sender, GridViewUpdateEventArgs e)
{
MySqlConnection con = new MySqlConnection(strConnString);
string id_peraturan = GridView1.DataKeys[e.RowIndex].Value.ToString();
FileUpload FileUpload1 = (FileUpload)GridView1.Rows[e.RowIndex].FindControl("FileUpload1") as FileUpload;
FileUpload FileUpload2 = (FileUpload)GridView1.Rows[e.RowIndex].FindControl("FileUpload2") as FileUpload;
FileUpload FileUpload3 = (FileUpload)GridView1.Rows[e.RowIndex].FindControl("FileUpload3") as FileUpload;
string fileName1 = string.Empty;
string fileName2 = string.Empty;
string fileName3 = string.Empty;
string perda1 = ("Pembentukan/"); //fle Pembentukan
string perda2 = ("Pengelolaan/"); //file pengelolaan
string perda3 = ("Retribusi/"); //file retribusi
if (FileUpload1.HasFile)
fileName1 = Path.GetFileName(FileUpload1.FileName);
if (FileUpload2.HasFile)
fileName2 = Path.GetFileName(FileUpload2.FileName);
if (FileUpload3.HasFile)
fileName3 = Path.GetFileName(FileUpload3.FileName);
if (FileUpload1.HasFile)
{
perda1 += FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("Pembentukan/") + fileName1);
}
if (FileUpload2.HasFile)
{
perda2 += FileUpload2.FileName;
FileUpload2.PostedFile.SaveAs(Server.MapPath(perda2));
}
if (FileUpload3.HasFile)
{
perda3 += FileUpload3.FileName;
FileUpload3.PostedFile.SaveAs(Server.MapPath(perda3));
}
con.Open();
MySqlCommand update = new MySqlCommand("UPDATE tbl_peraturan SET namafile1='" + fileName1 + "',perda_pembentukan='" + perda1 + "',fileName1='" + fileName2 + "',perda_pengelolaan='" + perda2 + "',fileName3='"+fileName3+"',perda_retribusi='" + perda3 + "' WHERE ID_PERATURAN=" + id_peraturan + " ", con);
update.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
tampilgird();
}
Munesh SharmaPosted Feb 9, 2015, 5:01 AM
http://www.dotnetfox.com/articles/file-upload-in-gridview-Asp-Net-1008.aspx
Francis SusaimichaelPosted Feb 9, 2015, 4:08 AM