This is a migrated thread and some comments may be shown as answers.

FileUpload in Radgrid

5 Answers 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jimmie
Top achievements
Rank 1
Jimmie asked on 15 Jan 2009, 01:50 AM
I have sserious problem. I have placed a grid with an EditInForm. In the form one of the fields is a template form that has a FileUpload control. I want to read and save the file name then save the path to the database. My problem is that I cannot locate the FileUpload control in the itemcommand event handler. HELP!

 

<rad:GridTemplateColumn DataField="Attachment" FilterImageUrl="\\we03vdchc\RadControls\Skins\Vista\Filter.gif"

 

 

HeaderText="Attachment" SortAscImageUrl="\\we03vdchc\RadControls\Skins\Vista\SortAsc.gif"

 

 

SortDescImageUrl="\\we03vdchc\RadControls\Skins\Vista\SortDesc.gif" UniqueName="Attachment" ColumnEditorID="Attachment">

 

 

<EditItemTemplate>

 

 

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

 

 

<asp:Label ID="attachNameLBL"

 

 

runat="server" Text='<%# Bind("Attachment") %>'>

 

 

</asp:Label><br />

 

 

<asp:LinkButton ID="attachLB"

 

 

runat="server"

 

 

CommandArgument='<%# Bind("MuniTransactionID") %>'

 

 

CommandName="AttachDetailDoc"

 

 

OnCommand="attachLB_Command"

 

 

Text="Attach Document"></asp:LinkButton>

 

 

</EditItemTemplate>

 

 

</rad:GridTemplateColumn>

 

 

</Columns>

 


I have not posted the entire control because of the size. Any help on the code behind would be appreciated.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 15 Jan 2009, 04:42 AM
Hi Jimmie,

The ItemCommnd event will fire when clicking on edit and update. It is possible to check which command button you clicked by checking e.CommandName inside ItemCommand event. You can try the following code to access FileUpload control which is inside the EditItemTemplate of RadGrid.

CS:
protected void RadGrid1_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e) 
    if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
    { 
        FileUpload control = e.Item.FindControl("detailFileAttachmentUL"as FileUpload; 
        string str= control.FileName; // file name 
        string path = control.PostedFile.FileName; // path 
    } 

Thanks,
Shinu.
0
Jimmie
Top achievements
Rank 1
answered on 15 Jan 2009, 02:36 PM
Shinu

Thanks I am testing now. It seems as though the second IF condition "IsInEditMode" is returning false. very strange because it is clearly in editmode.
  if (e.Item is GridEditableItem && e.Item.IsInEditMode

Ok I tested the following code. The A FileUpload control is returned as "control" but it is blank in that is has no postedFile or FileName which causes an exception on line 5. I have used the FileUpload control numerous times (never like this) and I cannot understand why the file is not posted!

protected void RadGrid1_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e) 
    if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
    { 
        FileUpload control = e.Item.FindControl("detailFileAttachmentUL"as FileUpload; 
        string str= control.FileName; // file name 
        string path = control.PostedFile.FileName; // path 
    }
 
Any ideas would be greatly appreciated. I am stumped.
 
0
Jimmie
Top achievements
Rank 1
answered on 28 Apr 2009, 09:42 PM
Folks

I apologize for the delay getting back to the post. I resolved this issue. This may have been a major newbie error but I had the RadUpload inside of an Updatepanel. The partial postback was not working with the RadUpload so I created a Full Postback Trigger on the Updatepanel and it started working.

Thanks
0
you
Top achievements
Rank 1
answered on 29 May 2010, 12:41 AM
Could you show the code which resolved your the Fileupload issue in radgrid
0
John
Top achievements
Rank 1
answered on 26 Apr 2021, 07:41 AM

after allot of pain - i switched to using asp:radupload 

as per this :-

https://www.telerik.com/forums/problem-with-asp-fileupload-control-in-radgrid-edititemtemplate

 

Hello Praveen,

Check out the following example to access a RadUpload control in the ItemTemplate of a TemplateColumn.
aspx:
<telerik:GridTemplateColumn UniqueName="TemplateColumn">                       
             <ItemTemplate>    
                   ... 
              </ItemTemplate> 
              <EditItemTemplate>                          
                   <telerik:RadUpload ID="RadUpload1" runat="server"></telerik:RadUpload> 
              </EditItemTemplate> 
</telerik:GridTemplateColumn> 
c#:
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
      if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            RadUpload upload = (RadUpload)editItem.FindControl("RadUpload1");          
        }  
    } 
Thanks
Princy.

 

 

 

Tags
Grid
Asked by
Jimmie
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Jimmie
Top achievements
Rank 1
you
Top achievements
Rank 1
John
Top achievements
Rank 1
Share this question
or