views:

1375

answers:

0

I have nested repeaters that create a table with each cell consisting of 3 drop downs. I set the selected value of the drop downs by looping through the repeaters and assigning them to the result of a linq statement. The number and characteristic drop downs work fine, but the make drop downs all get set to the last value assigned. Does anyone have any clue why this is happening?

<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;
                    }

                }
            }