简体   繁体   English

更新面板内的 FileUpload GridView 未在按钮单击时上传文件

[英]FileUpload GridView inside Update Panel not Uploading Files on Button Click

File upload does not have files on update panel when outside Update panel on full postback this code will work.当在完整回发时在更新面板之外时,文件上传在更新面板上没有文件,此代码将起作用。

    <asp:UpdatePanel ID="updatepanelFixedIncome" runat="server">
        <ContentTemplate>      
           <asp:GridView ID="grdFixed" runat="server" ShowFooter="true" AutoGenerateColumns="false" Width="100%"
                     CssClass="Grid" AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr"
                  OnRowDataBound="grdFixed_RowDataBound" Visible="false">
                <Columns>
                 <asp:TemplateField HeaderText="Upload" HeaderStyle-Width="252px">
                     <HeaderStyle Width="15px" /><ItemStyle Width="15px" />
                     <ItemTemplate>
                         <asp:FileUpload runat="server" ID="FUPotrait" ToolTip="Select files to upload." AllowMultiple="false" Style="width: 177px;" EnableViewState="true" />
                         <asp:Button ID="cmdUploadFile" runat="server" Text="UPLOAD" OnClick="cmdUploadFile_Click"></asp:Button>
                    </ItemTemplate>
               </asp:TemplateField>
             </Columns>
            </asp:GridView>
        </ContentTemplate>
        <Triggers>
        </Triggers>
        </asp:UpdatePanel>

and the code goes like this on running file Upload always shows it has no files并且代码在运行文件上传时总是这样显示它没有文件

     protected void cmdUploadFile_Click(object sender, EventArgs e)
     {

                        Button btn = (Button)sender;
                        GridViewRow row = (GridViewRow)btn.NamingContainer;
                        HFGridviewRowID.Value = row.RowIndex.ToString();
                        FileUpload FUPotrait = (FileUpload)row.FindControl("FUPotrait") as FileUpload;
                        if (FUPotrait.HasFile)
                        {
                        }

            }

After a bit of research I found the solution, add another update panel to that particular item Template with both the parent and child updatemode as conditional经过一番研究,我找到了解决方案,将另一个更新面板添加到该特定项目模板,并将父和子更新模式作为条件

 <asp:UpdatePanel ID="updatepanelFixedIncome" runat="server" UpdateMode="Conditional">
            <ContentTemplate>      
               <asp:GridView ID="grdFixed" runat="server" ShowFooter="true" AutoGenerateColumns="false" Width="100%"
                         CssClass="Grid" AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr"
                      OnRowDataBound="grdFixed_RowDataBound" Visible="false">
                    <Columns>
                     <asp:TemplateField HeaderText="Upload" HeaderStyle-Width="252px">
                         <HeaderStyle Width="15px" /><ItemStyle Width="15px" />
                         <ItemTemplate>
                         <asp:UpdatePanel ID="FileUpPanel" runat="server" UpdateMode="Conditional">
                         <ContentTemplate>
                             <asp:FileUpload runat="server" ID="FUPotrait" ToolTip="Select files to upload." AllowMultiple="false" Style="width: 177px;" EnableViewState="true" />
                             <asp:Button ID="cmdUploadFile" runat="server" Text="UPLOAD" OnClick="cmdUploadFile_Click"></asp:Button>
                           </ContentTemplate>
                           <Triggers>
                                 <asp:PostBackTrigger ControlID="cmdUploadFile" />
                           </Triggers>
                           </asp:UpdatePanel>
                        </ItemTemplate>
                   </asp:TemplateField>
                 </Columns>
                </asp:GridView>
            </ContentTemplate>
            </asp:UpdatePanel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM