更新面板中的FileUpload GridView不能在单击按钮时上传文件

问题描述 投票:0回答:1

完整回发时,在“更新”面板上的外部没有文件时,此代码将起作用。

    <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>

并且代码在运行文件上是这样的,上传总是显示它没有文件

     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)
                        {
                        }

            }
c# asp.net .net gridview updatepanel
1个回答
0
投票

经过一番研究后,我找到了解决方案,在该特定项模板中添加了另一个更新面板,同时将父级和子级updatemode作为条件项>

 <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>
© www.soinside.com 2019 - 2024. All rights reserved.