Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Upload > Using radUpload in RadGrid
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Using radUpload in RadGrid

Feed from this thread
  • Posted on Oct 17, 2006 (permalink)

    When using radUpload in RadGrid can not find:
     foreach (UploadedFile file in fileUpload.UploadedFiles)

    <---Code Cs-->

    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "PerformInsert" || e.CommandName=="Update")
            {
                RadUpload fileUpload = new RadUpload();
                fileUpload = (RadUpload)e.Item.FindControl("uploadDocument");
                if (fileUpload != null)
                {
                    foreach (UploadedFile file in fileUpload.UploadedFiles)
                    {
                    file.SaveAs(Path.Combine(@"E:\Project\EPM_site\EPM Website\EPM\ProjectInfo\DocumentUpload\", file.GetName()), true);
                        fullFileName = @"E:\Project\EPM_site\EPM Website\EPM\ProjectInfo\DocumentUpload\" + file.FileName;
                      
                    }
                }
            }
        }

  • Valeri Hristov Valeri Hristov admin's avatar

    Posted on Oct 18, 2006 (permalink)

    Hi Quan,

    From your code I assume that the UploadedFiles collection does not contain any files even when you select files in RadUpload. Am I right?

    If this is the case, the reason for the problem might be enabled AJAX functionality of RadGrid:
    RadGrid1.EnableAJAX = true

    The resolution is to either set EnableAJAX = false, or use the workaround, described in the Uploading Files in AJAX.

    Sincerely yours,
    Valeri Hristov (Senior Developer, MCSD)
    the telerik team

  • Posted on Oct 18, 2006 (permalink)

    In my solution:
          radDocumentVersion.EnableAJAX=fase
    But it can not found :

     foreach (UploadedFile file in fileUpload.UploadedFiles)

    <--ASPX-->
    <radG:RadGrid ID="radDocumentVersion" runat="server" AllowSorting="True"
                  ShowFooter="true" ShowHeader="true"
                 
                   EnableAJAXLoadingTemplate="True" EnableAJAX="False"
                  
        

  • Valeri Hristov Valeri Hristov admin's avatar

    Posted on Oct 19, 2006 (permalink)

    Hi Quan,

    I do not understand very well what your problem is. Can you please open a support ticket and attach your project and a screenshot of the error?

    Kind regards,
    Valeri Hristov (Senior Developer, MCSD)
    the telerik team

  • Posted on Oct 26, 2006 (permalink)

    could you mind show me an example of using radUpload in radGrid. I want to upload a file when adding or editing an item in radGrid.

    Best regard !

  • Valeri Hristov Valeri Hristov admin's avatar

    Posted on Oct 30, 2006 (permalink)

    Hi quan,

    Please, find attached the requested example.

    Greetings,
    Valeri Hristov (Senior Developer, MCSD)
    the telerik team
    Attached files

  • Badrinarayanan avatar

    Posted on Apr 21, 2008 (permalink)

    Hi,
    I tried with the above given example.  But the event 

    RadGrid1_UpdateCommand 

     is getting called after postback.  Due to this the control gets cleared.  Hence the count of uploadedfiles within the foreach loop don't work.  Please help me in solving this problem

  • Badrinarayanan avatar

    Posted on Apr 21, 2008 (permalink)

    Hi,
    I tried with the above given example.  But the event 

    RadGrid1_UpdateCommand 

     is getting called after postback.  Due to this the control gets cleared.  Hence the count of uploadedfiles within the foreach loop don't work.  Please help me in solving this problem

  • Sophy Sophy admin's avatar

    Posted on Apr 21, 2008 (permalink)

    Hello,

    The previously attached example demonstrates how you can add a RadUpload control in a RadGrid's edit template and using an asp button to upload the selected file. When clicking on the Upload button a postback occurs and the selected files get uploaded, the RadGrid1_UpdateCommand is fired and the UploadedFiles collection contains the uploaded files.

    Could you please let me know what is the result you expect and the one you observe testing this example? I would like to also request for a list of steps which we can follow to reproduce the problem you experience.

    I suggest you also take a look at a much complicated online example which demonstrates using RadUpload in Ajax-enabled RadGrid.

    Best regards,
    Sophy
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • Pradeep avatar

    Posted on May 20, 2009 (permalink)

    In Rad Grid ( Edit form setting ) how to  Find Text box and File upload  ID in Click of Button

    Urgent Please help me Telerik Team........


    its very-2 urgent

  • Posted on May 21, 2009 (permalink)

    Hello Pradeep,

    You can try out the following code to access the textbox and fileupload controls within the edit form on click of the button which is also placed inside the formtemplate:
    aspx:
    <EditFormSettings EditFormType="Template" > 
            <FormTemplate> 
                <asp:TextBox ID="Textbox"  runat="server"></asp:TextBox> 
                <asp:FileUpload ID="FileUpload" runat="server" /> 
                <br /> 
                <asp:Button ID="Button" runat="server" OnClick="Button_Click" Text="Button" /> 
            </FormTemplate> 
    </EditFormSettings> 

    c#:
    protected void Button_Click(object sender, EventArgs e)   
        {   
            Button btn = (Button)sender;   
            GridEditFormItem editFormItem = (GridEditFormItem)btn.NamingContainer;// access the EditFormItem  
            TextBox txtbx = (TextBox)editFormItem.FindControl("Textbox");   
            FileUpload upload = (FileUpload)editFormItem.FindControl("FileUpload");   
        }   
     

    -Princy.

  • Genady Sergeev Genady Sergeev admin's avatar

    Posted on May 21, 2009 (permalink)

    Hi Pradeep,

    Princy is completely correct, the correct way to obtain references for an items inside a container is to call the FindControl method of the respective container. You can hook on the Insert/UpdateCommand events and then search for controls like this:

       protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            Control control = e.Item.FindControl("ControlName") as Control;    
        } 


    Sincerely yours,
    Genady Sergeev
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.

  • pradeep avatar

    Posted on Aug 19, 2009 (permalink)

    Hello Genady Sergeev
     i want to find ID Click of Edit Button (This edit will be generate of Radgird Colomn)
    and Also Click of Add New Item

    <

    telerik:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton"

     

     

    HeaderStyle-BackColor="#169fd3" HeaderStyle-CssClass="paddingleft10 whiteheading">

     

     

    <HeaderStyle Width="20px" />

     

     

    <ItemStyle CssClass="MyImageButton" />

     

     

    </telerik:GridEditCommandColumn>

     

    protected

    void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)

     

    {

     

     

    I want to Find Here This ID
    }

    Please Help Me its very Urgent-2

  • Posted on Aug 20, 2009 (permalink)

    Hello Pradeep,

    The EditCommand and InitInsert commands are too early events to access the edit form controls so you should rather, try to access the control in the ItemDataBound event as shown below:
    c#:
    protected void RadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
        { 
            if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) // which will fire on clicking the Edit or the AddNewRecord buttons 
            { 
                GridEditableItem item = (GridEditableItem)e.Item; 
                Control cntrl = (Control)item.FindControl("ControlID");        
                
            } 
        } 

    Thanks
    Princy.

  • Aleks A avatar

    Posted on Oct 20, 2009 (permalink)

    I have this for upload in radgrid popup that works fine:

               
       <EditFormSettings EditFormType="Template"
                            <EditColumn UniqueName="EditCommandColumn1"
                            </EditColumn> 
                            <FormTemplate> 
                                You can use traditional data binding<br /> 
                                Which require you to handle the updates yourself<br /> 
                                Name: 
                                <asp:TextBox ID="txtName" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.Name" ) %>'
                                </asp:TextBox><br /> 
                                <input type="file" runat="server" id="inputFile" /> 
                                <telerik:RadProgressManager ID="Radprogressmanager1" runat="server" Skin="Vista" /> 
                                <telerik:RadProgressArea ID="RadProgressArea1" runat="server" Skin="Vista" /> 
                                <asp:button runat="server" id="ButtonCancel" text="Cancel" commandname="Cancel" /> 
                                <asp:button runat="server" id="ButtonUpload" text="Upload" commandname="Update" /> 
                                <div> 
                                    <asp:Image ID="PreviewImage" ImageUrl="" runat="server" Visible="true" /> 
                                </div> 
                                <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' 
                                    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                </asp:Button> 
                            </FormTemplate> 
                            <PopUpSettings ScrollBars="None" /> 
                        </EditFormSettings> 

    And in my codebehind
     
    protected void RadGridCardDetails_UpdateCommand(object source, GridCommandEventArgs e) 
            { 
     
            HtmlInputFile htmlInputFile = editFormItem.FindControl("inputFile") as HtmlInputFile; 
                        UploadedFile file = UploadedFile.FromHttpPostedFile(Request.Files[htmlInputFile.UniqueID]); 
     
                        file.SaveAs(String.Concat(targetFolder + targerCategory +"\\" +file.FileName), true); 
                        editFormItem.Display = false

  • Arun avatar

    Posted on Apr 19, 2011 (permalink)

    hi Pricy

    please go throug the code sinpper the problem is that i could not abel to get the file name ......can u assest


     

    .ASPX

    EditFormSettings EditFormType="Template" > 

            <FormTemplate> 

                <asp:TextBox ID="Textbox"  runat="server"></asp:TextBox> 

                <asp:FileUpload ID="FileUpload" runat="server" /> 

                <br /> 

                <asp:Button ID="Button" runat="server" OnClick="Button_Click" Text="Button" /> 

            </FormTemplate> 

    </EditFormSettings> 

    •  


    .ASPX.CS

     

    protected void Button_Click(object sender, EventArgs e)   

        {   

            Button btn = (Button)sender;   

            GridEditFormItem editFormItem = (GridEditFormItem)btn.NamingContainer;// access the EditFormItem  

            TextBox txtbx = (TextBox)editFormItem.FindControl("Textbox");   

            FileUpload upload = (FileUpload)editFormItem.FindControl("FileUpload");   

        }   

     

    •  







  • Genady Sergeev Genady Sergeev admin's avatar

    Posted on Apr 22, 2011 (permalink)

    Hi Arun,

    The easiest way to access the name of the uploaded files is to use

    var name = Request.Files[0].FileName;

    Apart from this, does the following line retrieve an instance of RadUpload?

    FileUpload upload = (FileUpload)editFormItem.FindControl("FileUpload");

    Greetings,
    Genady Sergeev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Upload > Using radUpload in RadGrid