请问我下面的后台代码为什么数据绑不到前台数据控件上去呢?请高人指点啊!
前台代码:
<asp:ListView ID="ListView1" runat="server" OnItemDataBound="ListView1_ItemDataBound">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<div>
<asp:HyperLink runat="server" ID="hpProImg">
<asp:Image runat="server" ID="imgPro" Width="103" Height="80" border="0" />
</asp:HyperLink>
</div>
<asp:Repeater ID="PTypeList" runat="server" EnableViewState="false">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<%# Eval("Name") %>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:ListView>
后台数据绑定:
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Repeater Detail = (Repeater)e.Item.FindControl("PTypeList");
Image imgPro = (Image)e.Item.FindControl("imgPro");
HyperLink hpProImg = (HyperLink)e.Item.FindControl("hpProImg");
DataView dv = ShopFunc.GetCommHot(m_TypeID, m_Num).DefaultView;
if (dv.Count > 0 && !StringUtil.IsEmpty(dv[0]["PicSmall"].ToString()))
{
imgPro.ImageUrl = dv[0]["PicSmall"].ToString();
hpProImg.NavigateUrl = "../" + string.Format(UrlFormat.GetUrlFormat("ProductUrl"), dv[0]["ProductId"].ToString());
Detail.DataSource = dv;
}
else
{
imgPro.ImageUrl = "../Images/Blank.gif";
}
Detail.DataBind();
}
}
Repeater +后台绑定时判断e.Item.ItemType == ListViewItemType.DataItem还要加上判断e.Item.ItemType == ListViewItemType.AlternativeDataItem 这个交替模板.之前我试过就有这个情况,不知道您的是不是一样.只有奇数行绑定成功.