File Upload
-
I have a gridview with a file upload:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" DataKeyNames="Program_ID" Width="387px">
<Columns>
<asp:BoundField DataField="Program_ID" HeaderText="Program ID" SortExpression="Program_ID" />
<asp:TemplateField HeaderText="Image Files for Program">
<ItemTemplate>
<asp:FileUpload ID="fileUpload" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>For some reason, on postback, I am not getting any value from the file upload control:
//Button Click
foreach (GridViewRow row in GridView2.Rows)
{
FileUpload fileUpload = (FileUpload)row.FindControl("fileUpload");
//Response.Write(fileUpload.FileName);
if (!String.IsNullOrEmpty(fileUpload.FileName.Trim()))
{
// use the first file name for all if checkbox is checked.
if (chkImageFile.Checked)
{
if (String.IsNullOrEmpty(tempFileName))
{
tempFileName = fileUpload.FileName;
fileUpload.SaveAs(Server.MapPath("~/"));
}
}
else
tempFileName = fileUpload.FileName;
}
}Any idea whats going on? P.S. I am using ajax but for this task a i am doing a complete postback. None of the controls listed here are inside an update panel.
-
I have a gridview with a file upload:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" DataKeyNames="Program_ID" Width="387px">
<Columns>
<asp:BoundField DataField="Program_ID" HeaderText="Program ID" SortExpression="Program_ID" />
<asp:TemplateField HeaderText="Image Files for Program">
<ItemTemplate>
<asp:FileUpload ID="fileUpload" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>For some reason, on postback, I am not getting any value from the file upload control:
//Button Click
foreach (GridViewRow row in GridView2.Rows)
{
FileUpload fileUpload = (FileUpload)row.FindControl("fileUpload");
//Response.Write(fileUpload.FileName);
if (!String.IsNullOrEmpty(fileUpload.FileName.Trim()))
{
// use the first file name for all if checkbox is checked.
if (chkImageFile.Checked)
{
if (String.IsNullOrEmpty(tempFileName))
{
tempFileName = fileUpload.FileName;
fileUpload.SaveAs(Server.MapPath("~/"));
}
}
else
tempFileName = fileUpload.FileName;
}
}Any idea whats going on? P.S. I am using ajax but for this task a i am doing a complete postback. None of the controls listed here are inside an update panel.
Could it be that the control be getting updated in another method being fired before the button click event? I've never tried a fileupload in a gridview though.
I didn't get any requirements for the signature