Skip to main content

FileUpload in Gridview inside UpdatePanel

Some time we need to do such a task like to refreshing data from server side at binding a dropdown at another dropdown selected index change, then we go for the updatepanel to not posting the whole page to server side and get response faster, but what happen when there is a requirement of fileupload to attach some file and we need to place that fileupload inside that updatepanel, file upload doesn't work because file upload need always post the file to server with form data means file upload need a full post back to server for that solution is as simple just add a post back trigger for the button control in which you need to upload file to server but there is another situation when file upload inside the gridview or datalist for doing the task row wise , we cannot add a trigger for the control that placed inset the data bind control and cannot add trigger at runtime in databound event of that particular databind control so what is the solution for that.


Below is the solution for this type of situation you need to add another updatepanel  for fileupload control inside gridview and need to add full postback trigger for upload button control just like shown below in yellow color.




<asp:ScriptManager runat="server" ID="scm"></asp:ScriptManager>

<asp:UpdatePanel runat="server" ID="upMain" UpdateMode="Conditional">
 <ContentTemplate>

  <asp:GridView AutoGenerateColumns="False" runat="server" ID="dt">
  <Columns>
    <asp:TemplateField HeaderText="Catagory">
        <ItemTemplate>
            <asp:DropDownList runat="server" ID="ddlSubCat">
            </asp:DropDownList>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="SubCatagory">
        <ItemTemplate>
            <asp:DropDownList runat="server" ID="ddlCat">
            </asp:DropDownList>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Attachments">
        <ItemTemplate>
          

     <asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="updFU">
                <ContentTemplate>
       <asp:FileUpload runat="server" ID="updCon" /><asp:Button runat="server" ID="btnUpload"
                        Text="Upload" />
            </ContentTemplate>
            <Triggers>
              <asp:PostBackTrigger ControlID="btnUpload" />
            </Triggers>
      </asp:UpdatePanel>
       

    </ItemTemplate>
    </asp:TemplateField>
  </Columns>
  </asp:GridView>

 </ContentTemplate>
</asp:UpdatePanel>


Popular posts from this blog

Merging multiple PDFs using iTextSharp in asp.net c#

In this article i will show you how to merge multiple pdfs into one using ITextSharp below is the two approach one is to pass your input files path, output file path (will be created if not exist) and another is pass direct input stream, output stream and it will write the merge files into output stream.

how $document.ready() is different from window.onload()

we often use window.onload() in javascript and $document.ready() in jquery and assume that both are same just jquery library wrap up javascript window.onload() and introduce $document.ready() but no there is much difference between them below is the explanation -

Uploading large file in chunks in Asp.net Mvc c# from Javascript ajax

Often we have a requirement to upload files in Asp.net, Mvc c# application but when it comes to uploading larger file, we always think how to do it as uploading large file in one go have many challenges like UI responsiveness, If network fluctuate for a moment in between then uploading task get breaks and user have to upload it again etc.

How to handle click event of linkbutton inside gridview

Recently I have posted how to sort only current page of gridview, Scrollble gridview with fixed header through javascript, File upload control inside gridview during postback and now i am going to explain how to handle click event of linkbutton or any button type control inside gridview.

We can handle click event of any button type control inside gridview by two way first is through event bubbling and second one is directly (in this type of event handling we need to access current girdviewrow container)

Scrollable Gridview with fixed headers in asp.net

horizontal and vertical scrollable Gridview with static header row.fixed header in gridview in asp.net.static header in gridview through java script.I was looking for a solution for this for a long time and found most of the answers are not working or not suitable for my situation i also find most of the java script code for that they worked but only with the vertical scroll not with the horizontal scroll and also combination of header and rows doesn't match.