我有嵌套的转发器创建一个表,每个单元格包含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;
}
}
}