![](/img/trans.png)
[英]Gridview inside Update panel PageIndex not maintained on button click
[英]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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.