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