【发布时间】:2016-03-25 14:15:05
【问题描述】:
大家早上好。我一直在使用应该是一个带有转发器和动态对象列表的简单网站。我使用包含四个其他对象的四个列表属性的父对象设置我的数据。
请求(父)
- 事件
- 航班
- 酒店
-
汽车
<asp:Repeater ID="rptEvent" runat="server" EnableViewState="false"> <ItemTemplate> <table class="tableStyle"> <tr> <td colspan="4" class="headerLabel"> CLIENT EVENT INFORMATION - <%# Eval("ProjectName") %> </td> </tr> <tr> <td class="regLabel row1">Company Name: (If Billable)</td> <td colspan="3" class="row1"> <asp:DropDownList ID="cboClientName" runat="server" AutoPostBack="true" CssClass="dropDownClass1" DataSource='<%# Eval("ClientName") %>' SelectedValue='<%# Eval("SelectedClientName") %>' ClientIDMode="Static" OnSelectedIndexChanged="cboClientName_SelectedIndexChanged"></asp:DropDownList> </td> </tr> [...more items...] </table> <asp:Panel runat="server" ID="pnlAdd" Visible="<%# Container.ItemIndex + 1 == tempRequest.events.Count && tempRequest.events.Count < 3 %>"> <asp:Label runat="server" CssClass="regLabel" Text="Would you like to add another destination? " /> <asp:CheckBox ID="inptAdditionalInfo" AutoPostBack="true" runat="server" OnCheckedChanged="inptAdditionalInfo_CheckedChanged" /><br /><br /> </asp:Panel> </ItemTemplate> </asp:Repeater>
这里发生的情况是页面最初加载每个属性列表中的一个对象,并且一切都很棒并且看起来很棒。每个对象都包含不同的属性类型。字符串列表、单个字符串属性、日期时间属性等,我认为将这些值绑定到对象的正确语法。但是,当用户选中复选框以添加更多项目时,问题就出现了。
页面会在其他任何事情发生之前重新加载,这会创建初始数据的“重新启动”,并且数据不会持续存在。我在后面的代码中有一个更新方法,我认为它可以正常工作。
protected void UpdateRequest() {
for (int i = 0; i <= tempRequest.events.Count - 1; i++)
{
// Set the Event ===============================================================================
var temp = (DropDownList)rptEvent.Items[i].FindControl("cboClientName");
tempRequest.events[i].SelectedClientName = temp.SelectedItem.ToString();
它不起作用,我没有得到持久数据。如何正确地将每个转发器控件的值绑定到正确对象中的正确项? IE:ClientName 从中继器的第二个索引到对象列表的第二个索引?
我希望我已经为这个问题提供了足够的信息。
【问题讨论】: