我有两个存储项目和项目大小的表,一个项目将有不同的大小。我正在尝试在数据列表中显示下拉列表中项目的项目大小。我的html如下
<asp:DataList ID="dlstCartItems" runat="server" RepeatDirection="Horizontal" RepeatColumns="5"
Width="580px" ForeColor="Blue" DataKeys="ItemCode"
onitemdatabound="dlstCartItems_ItemDataBound">
<ItemTemplate>
<table cellpadding="0" cellspacing="0" style="border: Solid 2px #eeeeee;">
<tr>
<td align="left" style="width: 180px;">
<a href="Videos.aspx?vid=<%# Eval("itemid") %>">
<img src="images/Gallery/<%# Eval("imagename") %>" alt="Image" height="120px" width="185px"
style="border: 0;" />
</a>
</td>
</tr>
<tr>
<td style="width: 180px;" align="left">
<table>
<tr>
<td>
Name:
</td>
<td>
<a href="Videos.aspx?vid=<%# Eval("itemid") %>">
<asp:Label ID="lblVideoName" runat="server" Text='<%# Eval("name")%>' ForeColor="#06C"></asp:Label>
</a>
</td>
</tr>
<tr>
<td>
Author:
</td>
<td>
<a href="Videos.aspx?Authorid=<%# Eval("itemid") %>">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("thm") %>' ForeColor="#06C"></asp:Label></a>
</td>
</tr>
<tr>
<td>
Technology:
</td>
<td>
<a href="Videos.aspx?Techid=<%# Eval("itemid") %>">
<asp:Label ID="Label2" runat="server" Text='<%# Eval("itemcode") %>' ForeColor="#06C"></asp:Label></a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="ddlAvailableSizes" runat="server" >
</asp:DropDownList>
</td>
</tr>
</table>
</ItemTemplate>
<%--<AlternatingItemStyle BackColor="Silver" />--%>
<ItemStyle BackColor="#eeeeee" />
</asp:DataList>
This is my bind method
var query = (from b in db.CR_CartItems
join c in db.CR_CartItems_Sizes on b.ItemCode equals c.ItemCode
join k in db.CR_ScrollingMenus on b.ThemeID equals k.MenuID
where b.status == true
orderby b.updatedat descending
select new
{
itemid = b.Itemid,
imagename = b.galleryimg,
itemcode = b.ItemCode,
thm = k.DisplayName,
name = b.posterName
}).Distinct();
foreach (var q in query)
{
var query1 = from b in db.CR_CartItems_Sizes
join c in db.CR_CartItems on b.ItemCode equals c.ItemCode
where b.ItemCode == q.itemcode
select new
{
b.SizeDesc,
b.ItemCode
};
foreach (DataListItem li in dlstCartItems.Items)
{
DropDownList list = (DropDownList)li.FindControl("ddlAvailableSizes");
list.DataSource = query1;
list.DataTextField = "SizeDesc";
list.DataValueField = "ItemCode";
list.DataBind();
list.Items.Insert(0, "Available Sizes");
}
}
dlstCartItems.DataSource = query;
dlstCartItems.DataBind();
}
我在 foreach 循环中设置了一个断点并检查,它没有进入循环。任何帮助表示赞赏。