Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir, i have a gridview. I which i have a fileupload button and one image button and a textbox.
when i upload any file and click on image button then upload file name show in a text box. but fileupload button are refresh and and uploaded file are missing. what can i do now.


here is my code:

.aspx--->>

ASP.NET
<asp:TemplateField HeaderText="Upload File" HeaderStyle-HorizontalAlign="Center">

<Hari:Fileupload ID="FileUpload1"  runat="server" Width="180px" size="25" CssClass="button" />
<asp:ImageButton ID="ImgFileName" CausesValidation="False" ImageUrl="~/Images/arrow.png" Width="17px" runat="server" OnClick="x" />



<asp:TemplateField HeaderText="File Name" HeaderStyle-HorizontalAlign="Center">

<asp:TextBox ID="TxtFileName" Width="100px" runat="server" >




.vb--->


VB
Public Sub x()
       Dim cmd As New SqlCommand With {.Connection = Hari.Utility.dbutility.Con}
       For Each row As GridViewRow In GridView1.Rows

           If CType(row.FindControl("FileUpload1"), FileUpload).HasFile Then
               Dim fileName As String = Path.GetFileName(CType(row.FindControl("FileUpload1"), FileUpload).PostedFile.FileName).ToString
               CType(row.FindControl("FileUpload1"), FileUpload).PostedFile.SaveAs((Server.MapPath("~/photos/doc/") + fileName))

               Dim doc As String() = Split(fileName, ".")
               Dim FName As String = doc(0)
               CType(row.FindControl("TxtFileName"), TextBox).Text = FName

               fpath = "~/photos/syllabus/" + fileName




           End If

       Next

   End Sub
Posted
Updated 26-Aug-14 21:07pm
v2

1 solution

Use Ajax update Panel to avoid the refresh.

see this link for update panel
http://ajax.net-tutorials.com/controls/updatepanel-control/[^]
 
Share this answer
 
Comments
TCS54321 27-Aug-14 6:39am    
this is my code :


<asp:TemplateField HeaderText="Upload File" HeaderStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional" >
<Triggers>
<asp:PostBackTrigger ControlID="ImgFileName" />
</Triggers>
<contenttemplate>

<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:ImageButton ID="ImgFileName" CausesValidation="False" ImageUrl="~/Images/arrow.png" Width="17px" runat="server" OnClick="x" />







but its not working..
TCS54321 27-Aug-14 6:40am    
when i click on image button to show file name in this textbox:-

<asp:TemplateField HeaderText="File Name" HeaderStyle-HorizontalAlign="Center">
<itemtemplate>
<asp:TextBox ID="txtFName" Width="100px" runat="server" >



then filename from Fileupload button are missing.
vangapally Naveen Kumar 27-Aug-14 7:44am    
See this link you will get an Idea.
http://www.codeproject.com/Answers/228370/how-to-manage-file-upload-control-inside-grid-view#answer3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900