Search code examples
c#gridviewuploadedititemtemplate

In Edit template Upload file in GridView on c#


I my GridView in c# I need upload one file in EditItemTemplatemode:

<asp:TemplateField HeaderText="File attachement">
    <ItemTemplate>
        <asp:HyperLink ID="attachement" runat="server" NavigateUrl='<%# Eval("attachement").ToString() %>'
            ImageUrl='<%#(String.IsNullOrEmpty(Eval("attachement").ToString()) ? "/Images/cross-button.png" : "/Images/download.gif")%>'
            Target="_blank" BorderStyle="None" ForeColor="Transparent" CssClass="ddl_Class_new">
        </asp:HyperLink>
    </ItemTemplate>
    <EditItemTemplate>
        <asp:FileUpload ID="attachement_edit" runat="server" CssClass="ddl_Class_new" BackColor="Orange" />
</asp:TemplateField>

The row update on GV and the file upload it worked, but If I need re-edit the same row I have problem because I don't see the uploaded file on first edit, but the re-edit it requires a new upload file.

It is possible in re-edit mode row in GV see the upload file on first edit ?

Can you help me?

Thank you in advance.


Solution

  • The FileUpload control will not show the file path string after posting back due to safety reason. You can add a HyperLink after the FileUpload control to link the first uploaded file (if you keep it on server). In its Text property you can show the file name the user just uploaded. If the user upload again, change the Text property to show the new file name and change the NavigateUrl to it.