Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6608707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:38:17+00:00 2026-05-25T19:38:17+00:00

Hello i try to add a fileupload inside of a detailsview i attach here

  • 0

Hello i try to add a fileupload inside of a detailsview i attach here some parts from my code:

<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="586px" 
        DefaultMode="Edit" AutoGenerateRows="False" BorderColor="White" 
        BorderStyle="None" DataSourceID="EntityDataSource1" GridLines="None" DataKeyNames="UserName" OnItemUpdated="DetailsView1_ItemUpdated" ONItemEditing="DetailsView1_ItemEditing">

then the fileupload control is placed inside of template field:

 <asp:TemplateField HeaderText="Foto">
                      <EditItemTemplate>


<asp:FileUpload ID="FileUpload1" runat="server" />
                         </EditItemTemplate>
     </asp:TemplateField>

and the datasource is :

 <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
        ConnectionString="name=mesteriEntities" DefaultContainerName="mesteriEntities" 
        EnableFlattening="False" EntitySetName="Users" 
         EnableUpdate="True" AutoGenerateWhereClause="True" 
    EnableInsert="True">
         <WhereParameters>
        <asp:SessionParameter Name="UserName" SessionField="New" Type="String" />
         </WhereParameters>
    </asp:EntityDataSource>

The code behind:

 protected void DetailsView1_ItemEditing(object sender, DetailsViewInsertEventArgs e)
    {
        FileUpload fu1 = (FileUpload)DetailsView1.FindControl("FileUpload1");
        if (fu1 == null)
            e.Cancel = true;
        if (fu1.HasFile)
        {
            try
            {
                string fileName = Guid.NewGuid().ToString();
                string virtualFolder = "~/UserPics/";
                string physicalFolder = Server.MapPath(virtualFolder);
               // StatusLabel.Text = "Upload status: File uploaded!";
                string extension = System.IO.Path.GetExtension(fu1.FileName);
                fu1.SaveAs(System.IO.Path.Combine(physicalFolder, fileName + extension));
                e.Values["foto"] = System.IO.Path.Combine(physicalFolder, fileName + extension);
            }
            catch (Exception ex)
            {
              Response.Write(ex.Message);
            }
        }
        else
            e.Cancel = true;



    }

I’m not sure why doesn’t work. It doesn’t upload the file on the server and doesn’t add reference inside database of the file . Whay i did wrong here?

thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:38:18+00:00Added an answer on May 25, 2026 at 7:38 pm

    As far as I can tell (from looking at the class documentation: DetailsView Class) there is no OnItemEditing event to handle?

    There is however a DetailsView.ItemUpdating event which looks like it could do the trick:

    Occurs when an Update button within a DetailsView control is clicked,
    but before the update operation.

    Also I think the FileUpload control cannot be found because the FindControl method is not searching the full hierarchy of controls it contains.

    Try using the following method and modifying your code like so:

    FileUpload fu1 = (FileUpload)FindControl(DetailsView1, "FileUpload1");
    
    ...
    
    private Control FindControl(Control parent, string id)
    {
        foreach (Control child in parent.Controls)
        {
            string childId = string.Empty;
            if (child.ID != null)
            {
                childId = child.ID;
            }
    
            if (childId.ToLower() == id.ToLower())
            {
                return child;
            }
            else
            {
                if (child.HasControls())
                {
                    Control response = FindControl(child, id);
                    if (response != null)
                        return response;
                }
            }
        }
    
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I'm new to iPhone development. I try to add move data from NSDictionary
hello guys i am try to eliminate all the duplicate strings from a string
When I try this code: dict_a = dict_b = dict_c = {} dict_c['hello'] =
I have a C++ DLL with code like this: LogMessage( Hello world ); try
Hello I'm creating an os x application for which I try to add a
I try adding objects to NSMutableArray from another class (secondViewController) and then add it
Hello I try to add multiple Buttons on a panel on form and next
Hello I have a ListFragment that fetches some data from the net and then
Hello there i'm having a problem here i have an add and edit form
ArrayList<String> myArr = new ArrayList<String>(); then add some stuff to it myArr.add(Hello); myArr.add(Testing); myArr.add(Testing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.