I use the asp:FileUpload in asp:GridView.FooterRow
and cannot access to the FileUpload control at code behind
please help me
tnx
design view:
design view:
-----------------------------------------------------------------------------------------------
code view:
protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
String path = Server.MapPath("~/Upload/Images/");
if (e.CommandName == "Insert")
{
description = new Description();
GridViewRow row = gv.FooterRow;
TextBox txtTitle = row.FindControl("txtTitle") as TextBox;
TextBox txtContent = row.FindControl("txtContent") as TextBox;
FileUpload fuImage = row.FindControl("fuImage") as FileUpload;
try
{
using (context = new DBEntities())
{
description.title = txtTitle.Text;
description.content = txtContent.Text;
description.image = path + fuImage.FileName;
if (File.Exists(Server.MapPath(path + fuImage.FileName)))
{
lblMessage.Text = " ";
}
else
{
((FileUpload)row.FindControl("fuImage")).SaveAs(Server.MapPath(path + fuImage.FileName));
lblMessage.Text = " ";
}
context.Descriptions.Add(description);
context.SaveChanges();
}
}
catch (Exception)
{
throw;
}
Response.Redirect("");
}
}
code view:
g sPosted Apr 7, 2015, 11:02 AM
http://screenshotdrizzles.blogspot.in/2014/10/image-insert-upload-bind-gridview-using.html
Khargesh RajputPosted Mar 22, 2015, 7:56 AM
Chnge id of.any one fileupload
Debug your code whether control is not file or fileupload has no file
Saineshwar BageriPosted Mar 22, 2015, 7:47 AM
And best way is to get all control out from footer and design like normal page and when user enter data display them in gridview.