Update gridview with fileupload
how Update gridview with fileupload
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Francis SusaimichaelRank #466 · 5.4K reputationPosted Feb 8, 2015, 11:08 PM EST
Munesh SharmaRank #174 · 13.9K reputationPosted Feb 9, 2015, 12:01 AM EST
http://www.dotnetfox.com/articles/file-upload-in-gridview-Asp-Net-1008.aspx
hothorasman panjaitan117 reputationPosted Feb 9, 2015, 12:16 AM EST
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 panjaitan117 reputationPosted Feb 9, 2015, 7:09 AM EST
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();
}