【发布时间】:2012-03-29 15:35:25
【问题描述】:
我有一个页面,其中包含一个包含在更新面板中的 ASP 占位符,我加载了一个用户控件和另一个包含在更新面板中的占位符。然后,我使用多个用户控件加载这个最新的占位符,每个用户控件都包含一个包装在更新面板中的 Gridview。
每个 Gridview 中的数据都基于“以前的”Gridview 中的数据,因此当用户编辑一行时,更改会沿 Gridview 向下级联,这就是我的问题所在。单击保存按钮后,什么都没有发生(数据库中的所有行都正确更新),直到我单击页面上任意位置的另一个按钮,此时所有更改都在 Gridviews 中明显更新。
我已经尝试了我能想到的所有方法来解决这个问题,没有结束使用更新面板选项和位置,通过 JavaScript 触发额外的按钮单击以及我能找到的任何其他似乎相关的解决方案,尽管没有一个解决方案我离我想去的地方更近了。
如果我设法以任何人都能理解的方式表达我的问题,我将不胜感激,如果您觉得我描述的内容不够清晰,请提出问题。
这里是三个级别和页面/用户控件/用户控件:
页面:
<div id="divCustomerProductInput">
<asp:UpdatePanel ID="udpSalesOrders" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:PlaceHolder ID="plhCsCustomerproductInput" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
第一个用户控件加载到上面的占位符中:
<asp:UpdatePanel ID="udpSalesOrders" runat="server" UpdateMode="Always" >
<ContentTemplate>
<asp:PlaceHolder runat="server" ID="plhProductionProcess"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
第二个用户控件多次加载到上面的占位符中:
<asp:UpdatePanel ID="udpPPI" runat="server" UpdateMode="Always">
<ContentTemplate>
<%-- MANUFACTURE--%>
<asp:GridView ID="gdvProductionProcessIngredients" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="lblId" runat="server" Text='<%# Eval("Id") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ingredient Description" ItemStyle-Width="21%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:Label ID="txtIngredientDescription" runat="server" Text='<%# Eval("IngredientDescription") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ingredient Code" ItemStyle-Width="14%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:Label ID="txtIngredientCode" runat="server" Text='<%# Eval("RmId") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="From" ItemStyle-Width="10%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:Label ID="txtParentDepartment" runat="server" Text='<%# Eval("ParentDepartment") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity (%)" ItemStyle-Width="10%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:TextBox ID="txtQuantityKg" runat="server" Text='<%# Eval("OldestAncestorQuantityPercent") %>'
ForeColor="Black"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Input Cost / Kg (£)" ItemStyle-Width="13%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:Label ID="lblCost" runat="server" Text='<%# Eval("InputCostKg") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Yield (%)" ItemStyle-Width="10%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:TextBox ID="txtYield" runat="server" Text='<%# Eval("Yield") %>' ForeColor="Black"></asp:TextBox></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Output Cost / Kg (£)" ItemStyle-Width="14%" ControlStyle-Width="95%">
<ItemTemplate>
<asp:Label ID="lblCostPerKg" runat="server" Text='<%# Eval("OutputCostKg") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="6%" ControlStyle-Width="95%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="btnDeleteIngredient" CommandName="REMOVE" CommandArgument='<%# Eval("Id") %>'
CssClass="btn danger hover" runat="server" Text="Remove" /></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
好的,下面是绑定和更新代码:
Dim myCsProductProductionProcessIngredients As New v2.Model.CsProductProductionProcessIngredientCollection
myCsProductProductionProcessIngredients.LoadByPPPId(_ProductProductionProcessId)
Me.gdvProductionProcessIngredients.DataSource = myCsProductProductionProcessIngredients
Me.gdvProductionProcessIngredients.DataBind()
Me.udpPPI.Update()
谢谢,科尔夫
【问题讨论】:
-
请发布一些示例代码。
标签: asp.net gridview user-controls updatepanel