更新面板内的 FileUpload GridView 不在单击按钮时上传文件
FileUpload GridView inside Update Panel not Uploading Files on Button Click
文件上传在更新面板上没有文件时,在完整回发的更新面板之外此代码将起作用。
<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)
{
}
}
经过一些研究我找到了解决方案,将另一个更新面板添加到该特定项目模板,同时将父子更新模式作为条件
<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>
文件上传在更新面板上没有文件时,在完整回发的更新面板之外此代码将起作用。
<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)
{
}
}
经过一些研究我找到了解决方案,将另一个更新面板添加到该特定项目模板,同时将父子更新模式作为条件
<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>