Terry

Terry

  • NA
  • 148
  • 0

Access a Control from EditItemTemplate and update a Property

Mar 23 2015 5:09 PM

Hi, 


   I have an ImageURL type field in my database. In my List I want to display that image & let the user browse image while editing & inserting. Image path saved in DB is : ~/CRMImages/Projects/vincitoreGardens/buildingLogo.png

In ItemTemplate, when I bind the property to Image, it gives error :
                       <!-- <asp:Image runat="server" ImageUrl='<%# Bind("UnitPlanImageUrl") %>' Width="30" Height="30" />  -->


Instead of binding, if I physically provide the same path to ImageUrl, then it works perfectly well :
                        <asp:Image runat="server" ImageUrl="~/CRMImages/Projects/vincitoreGardens/buildingLogo.png" Width="30" Height="30" />


In my EditItemTemplate, I have added a FileUpload control :
                    <td>
                        <asp:FileUpload runat="server" ID="unitPlanImgUpload" />  
                    </td>


I am not able to access unitPlanImgUpload control in UpdateMethod of the ListView. 
        public void unitPlanList_UpdateItem(int UnitPlanTypeId)
        {
           
            FileUpload img = unitPlanList.FindControl("unitPlanImgUpload") as FileUpload;  // REturns NULL
            if (img != null) {
                if (img.HasFile)
                {
                    System.Diagnostics.Debug.WriteLine("EDIT UNIT PLAN FILE NAME =" + img.FileName);
                }
            }


I believe, ItemBound event is to bind the data to something before editing/inserting. Here I want to access the control before updating and assign the filename to the property and save it on the server. I tried using unitPlanList.EditItemTemplate to find the control in EditItemtemplate, but unfortunately it doesn't have any Find method. 

Any idea what to do and how to access the file selected ??
Any help is highly appreciated.

Thanks





Answers (3)