嵌套更新面板问题
本文关键字:问题 更新 嵌套 | 更新日期: 2023-09-27 17:56:33
我有一个嵌套的更新面板像这样的东西
<asp:UpdatePanel ID="DetailsUpdatePanel" runat="server" Visible="false" UpdateMode="Conditional" >
<ContentTemplate>
<div><ajaxToolkit:AsyncFileUpload runat="server" ID="BrochureUpload" Width="400px"
OnClientUploadError="BrochureuploadError"
OnClientUploadStarted="BrochureStartUpload"
OnClientUploadComplete="BrochureUploadComplete"
CompleteBackColor="Lime" UploaderStyle="Modern"
ErrorBackColor="Red" ClientIDMode="AutoID"
ThrobberID="Throbber"
UploadingBackColor="#66CCFF"
onuploadedcomplete="BrochureUpload_UploadedComplete"/>
<asp:Label ID="Label1" runat="server" Style="display: none">
<asp:Image runat="server" ID="Image1" ImageUrl="~/Images/uploading.gif" />
</asp:Label>
<asp:Label ID="brochurelblstatus" runat="server" Style="font-family: Arial; font-size: small;"></asp:Label></div>
<div><asp:UpdatePanel runat="server" ID="child" UpdateMode="Conditional" >
<ContentTemplate>
<div>
<asp:GridView ID=GridView2" runat="server" AllowPaging="true" AutoGenerateColumns="false" CellPadding="0" CellSpacing="1" DataKeyNames="ArticleId">
<Columns>
<asp:BoundField DataField="ArticleId" HeaderText="ArticleId" ReadOnly="True" HeaderStyle-CssClass="td1" />
<asp:BoundField DataField="FileName" HeaderText="FileName" ReadOnly="True" HeaderStyle-CssClass="td2" />
<asp:TemplateField HeaderText="BrochureUrl">
<ItemTemplate>
<asp:HyperLink ID="lnkEPhoto" runat="server" BorderWidth="2px" NavigateUrl='<%# GetUrl(Eval("ArticleId"),Eval("FileName")) %>'
Target="_blank"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnRemove" runat="server" text="Delete" CommandName="Delete" CausesValidation="False" OnClientClick="DeleteOrNo()">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel></div>
</ContentTemplate>
</updatePanel>
代码隐藏:
protected void BrochureUpload_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
if(BrochureUpload.HasFile)
{
if(BrochureUpload.PostedFile.ContentLength<=3670016 )
{
var brochurePath = MapPath("~/") + Path.GetFileName(e.filename);
BrochureUpload.SaveAs(brochurePath);
using (var dataContext = new NewsStandAloneDataContext(Config.StandaloneNewsConnectionString))
{
var brochure = new xxx
{
Id = Convert.ToInt32(GridView1.SelectedValue),
FileName = Path.GetFileName(e.filename),
RecordCreated = DateTime.Now
};
dataContext.xxx.InsertOnSubmit(brochure);
dataContext.SubmitChanges();
}
bindGridView();//I have code to bind gridview
Child.Update();
}
}
}
protected void bindBrochureGridView()
{
using (var dataContext = new NewsStandAloneDataContext(Config.StandaloneNewsConnectionString))
{
var brochureList = (from brochure in dataContext.xxx
where brochure.ArticleId == Convert.ToInt32(GridView2.SelectedValue)
select new ArcticleBrochure
{
ArticleId = brochure.ArticleId.ToString(),
FileName = brochure.FileName
}).ToList();
GridView1.DataSource = brochureList;
GridView1.DataBind();
}
}
当我上传文件时,我希望更新子更新面板中的 giedview。但它不起作用任何想法?????
提前致谢
BrochureUpload_UploadedComplete
事件中调用child.Update();
。
protected void BrochureUpload_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
....................
....................
bindGridView();//I have code to bind gridview
child.Update();
}
文件上传完成后Child.Update()
调用包含网格视图的UpdatePanel
方法。您需要这样做,因为您设置了UpdateMode="Conditional"
在这种情况下,您必须在代码中手动更新它。
ChildrenAsTriggers="True"
在您的更新面板中。