代码之家  ›  专栏  ›  技术社区  ›  Bryan

填充嵌套中继器下拉列表

  •  1
  • Bryan  · 技术社区  · 16 年前

    我有嵌套的中继器,它们创建一个表,每个单元格由3个下拉列表组成。我通过遍历中继器并将其分配给linq语句的结果来设置下拉列表的选定值。
    “数字”和“特征”下拉列表工作正常,但“生成”下拉列表都设置为指定的最后一个值。有人知道为什么会这样吗?

    <table border="1">
            <tr>
                <th>Priority</th>
                <th>Monday</th>
                <th>Tuesday</th>
                <th>Wednesday</th>
                <th>Thursday</th>
                <th>Friday</th>
                <th>Saturday</th>
                <th>Sunday</th>
            </tr>
        <asp:Repeater id="PriorityRepeater" runat="server" OnItemDataBound="PriorityBound">
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:HiddenField ID="Priority" runat="server" Value='<%# Eval("Priority") %>' />
                        <%# Eval("Priority") %>
                    </td>
                    <asp:Repeater ID="DayRepeater" runat="server">
                        <ItemTemplate>
                            <td>
                                <asp:HiddenField ID="Day" runat="server" Value='<%# Eval("Day") %>' />
                                <!--%# Eval("Day") %-->
                                <label>Vehicles</label>
                                <asp:DropDownList id="dailyNumber_dd" runat="server">
                                    <asp:ListItem Text="5" />
                                    <asp:ListItem Text="10" />
                                    <asp:ListItem Text="15" />
                                    <asp:ListItem Text="25" />
                                    <asp:ListItem Text="30" />
                                    <asp:ListItem Text="35" />
                                    <asp:ListItem Text="40" />
                                    <asp:ListItem Text="45" />
                                </asp:DropDownList>
                                <br /><br />
                                <asp:DropDownList runat="server" id="dailyCharacteristic_dd" style="font-size:small">
                                    <asp:ListItem Text="New Inventory" Value="newest" />
                                    <asp:ListItem Text="Old Inventory" Value="oldest" />
                                    <asp:ListItem Text="Lowest Price" Value="cheap" />
                                    <asp:ListItem Text="Highest Price" Value="expensive" />
                                    <asp:ListItem Text="Oldest Year" Value="oldyear"/>
                                    <asp:ListItem Text="Newest Year" Value="newyear" Selected="True"/>
                                </asp:DropDownList>
                                <br /><br />
                                <asp:DropDownList runat="server" id="dailyMake_dd" Width="108" style="font-size:small"></asp:DropDownList>
                            </td>
                        </ItemTemplate>
                    </asp:Repeater>
                </tr>
            </ItemTemplate>
        </asp:Repeater>
        </table>
    
    
    foreach (RepeaterItem row in PriorityRepeater.Items)
                {
                    HiddenField myPriority = (HiddenField)row.FindControl("Priority");
                    Repeater DayRepeater = (Repeater)row.FindControl("DayRepeater");
                    foreach (RepeaterItem col in DayRepeater.Items)
                    {
                        DropDownList dailyMake_dd = (DropDownList)col.FindControl("dailyMake_dd");
                        DropDownList dailyNumber_dd = (DropDownList)col.FindControl("dailyNumber_dd");
                        DropDownList dailyCharacteristic_dd = (DropDownList)col.FindControl("dailyCharacteristic_dd");
                        HiddenField myDay = (HiddenField)col.FindControl("Day");
                        string thisDay = myDay.Value.ToString().ToLower();
                        string thisPriority = myPriority.Value.ToString();
    
                        tAutoSelection thisSelection = (from a in theSelections where a.day == thisDay select a).Single<tAutoSelection>();
                        if (thisPriority == "1")
                        {
                            //dailyMake_dd.SelectedValue = thisSelection.makes1;
                            dailyMake_dd.SelectedIndex = 5;
                            dailyNumber_dd.SelectedValue = thisSelection.num1.ToString();
                            dailyCharacteristic_dd.SelectedValue = thisSelection.char1;
                        }
                        else if (thisPriority == "2")
                        {
                            dailyMake_dd.SelectedIndex = 3;
                           // dailyMake_dd.SelectedValue = thisSelection.makes2;
                            dailyNumber_dd.SelectedValue = thisSelection.num2.ToString();
                            dailyCharacteristic_dd.SelectedValue = thisSelection.char2;
                        }
                        else if (thisPriority == "3")
                        {
                            dailyMake_dd.SelectedIndex = 9;
                           // dailyMake_dd.SelectedValue = thisSelection.makes3;
                            dailyNumber_dd.SelectedValue = thisSelection.num3.ToString();
                            dailyCharacteristic_dd.SelectedValue = thisSelection.char3;
                        }
    
                    }
                }
    
    0 回复  |  直到 12 年前