首页 新闻 搜索 专区 学院

asp.net控件OnItemDataBound事件数据绑定 急

0
悬赏园豆:10 [已关闭问题] 关闭于 2009-12-04 08:32

请问我下面的后台代码为什么数据绑不到前台数据控件上去呢?请高人指点啊!
前台代码:
   <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();
        }
    }

问题补充: ListView1控件在没有DataBind()前怎样触发ListView1_ItemDataBound事件 啊
凭栏处的主页 凭栏处 | 初学一级 | 园豆:45
提问于:2009-12-03 09:38
< >
分享
所有回答(1)
0

Repeater +后台绑定时判断e.Item.ItemType == ListViewItemType.DataItem还要加上判断e.Item.ItemType == ListViewItemType.AlternativeDataItem 这个交替模板.之前我试过就有这个情况,不知道您的是不是一样.只有奇数行绑定成功.

ERic Poon | 园豆:261 (菜鸟二级) | 2009-12-03 09:43
提示using System.Web.UI.WebControls.ListViewItemType并不包含AlternativeDataItem模板啊……怎么办啊?
支持(0) 反对(0) 凭栏处 | 园豆:45 (初学一级) | 2009-12-03 09:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册