gpt4 book ai didi

c# - 从 AsyncFileUpload uploadCompleted 事件中更新网格

转载 作者:行者123 更新时间:2023-11-30 22:47:26 24 4
gpt4 key购买 nike

我有以下代码,但无法更新 UpdatePanel。有任何想法吗?我想知道是否可以从异步方法中进行更新?

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DataGrid ID="dgFiles" runat="server" DataKeyField="ConfigurationFileId" AutoGenerateColumns="false" GridLines="None"
OnItemCommand="dgFiles_ItemCommand" Width="40%">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label ID="lblFile" runat="server" Text='<%#Eval("SourceFileName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="hypDelete" runat="server" Text="Delete" CssClass="blue" CommandName="Delete" CommandArgument="5"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<ajaxToolkit:AsyncFileUpload ID="Upload1" runat="server" UploaderStyle="Modern" Width="400px"
Style="visibility: hidden" OnUploadedComplete="Upload1_Complete" OnClientUploadComplete="UploadComplete" />

<asp:DataGrid ID="dgAddFiles" runat="server" DataKeyField="ConfigurationFileId" AutoGenerateColumns="false"
Width="40%" Style="visibility: hidden">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label ID="lblFile" runat="server" Text='<%#Eval("SourceFileName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="hypDelete" runat="server" Text="Delete" CssClass="blue" CommandName="Delete" CommandArgument="5"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</ContentTemplate>
</asp:UpdatePanel>




protected void Upload1_Complete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
if (Upload1.HasFile)
{
Upload1.SaveAs(Server.MapPath("~/files/temp/") + Upload1.FileName);
byte[] data = Upload1.FileBytes;
var file = new Files();
file.FileId = Guid.NewGuid();
file.FileName = Upload1.FileName;
file.Data = data;

using (var ctx = new DeviceManagerEntities())
{
ctx.AddToFiles(file);

ctx.SaveChanges();

var files = ctx.Files
.ToList();
dgAddFiles.DataSource = files;
dgAddFiles.DataBind();
UpdatePanel3.Update();
}
}
}

最佳答案

阅读this (Credit to Schelfaut.NET)看看它是否能解决您的问题:

关于c# - 从 AsyncFileUpload uploadCompleted 事件中更新网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2238136/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com