Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. File Upload

File Upload

Scheduled Pinned Locked Moved ASP.NET
sysadminarchitecturequestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    student_rhr
    wrote on last edited by
    #1

    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.

    T 1 Reply Last reply
    0
    • S student_rhr

      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.

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups