DataList嵌套DataList的邦定

14 篇文章 0 订阅
13 篇文章 0 订阅

  //前台代码

< asp : DataList   DataKeyField="Id"  ID="DataList1"   OnItemDataBound="DataList1_ItemDataBound" runat="server" >
                <ItemTemplate>
                    <table width="170" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>
                                <img src="images/h01.gif" width="175" height="8"></td>
                        </tr>
                        <tr>
                            <td valign="top" background="images/h02.gif">
                                <table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
                                    <tr>
                                        <td align="center" class="t05">
                                            <a href='twostage.aspx?id=<%# Eval("Id")%>' class="mon">
                                                <%# Eval("Name")%>
                                            </a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center">
                                            <asp:HyperLink ID="HyperLink1" Target="_blank" runat="server">
                                               <asp:Image ID="Image1" Width="80" Height="99" runat="server" />
                                            </asp:HyperLink>
                                        </td>
                                    </tr>
                                </table>
 
                                <asp:DataList ID="DataList2" runat="server">
                                    <HeaderTemplate>
                                        <table width="100%" border="0" style="text-align:left;" cellpadding="3" cellspacing="0">
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <tr>
                                            <td height="21" background="images/line.gif">
                                                <img src="images/icon02.gif" width="5" height="7">
                                                <a href='fivestage.aspx?id=<%# Eval("GoodsId") %>' target="_blank"><%# FHY.BLL.Uti.SqlText(Eval("GoodsName").ToString(),10,true,true) %></a>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td height="21" class="mon" background="images/line.gif">
                                                价格:¥<%# JiaGe(Eval("GoodsId"), Eval("JiageFanWei"))%> </a>
                                            </td>
                                        </tr>
                                    </ItemTemplate>
                                    <FooterTemplate>
                                        <tr>
                                            <td height="21" align="right" background="images/line.gif">
                                               <img src="images/icon03.gif" width="27" height="12"></td>
                                        </tr>
                                        </table>
                                    </FooterTemplate>
                                </asp:DataList>
 
                            </td>
                        </tr>
                    </table>
                    <table width="170" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>
                                <img src="images/h03.gif" width="175" height="8"></td>
                        </tr>
                    </table>
                </ItemTemplate>
                <ItemStyle VerticalAlign="Top" />
            </asp:DataList>
 
//后台代码
 
 
 
 
 protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex]);
            GoodsTuiJianDal tuijiandal = new GoodsTuiJianDal();
            DataView dv = tuijiandal.GetList_VW1(id).Tables[0].DefaultView;
            if (dv.Count > 0)
            {
                Image titlepic = (Image)e.Item.FindControl("Image1");
                titlepic.ImageUrl =FHY.BLL.Uti.ImageUrl(dv[0]["PicSrc"].ToString());
                HyperLink titleHyperLink = (HyperLink)e.Item.FindControl("HyperLink1");
                titleHyperLink.NavigateUrl = "~/fivestage.aspx?id=" + dv[0]["GoodsId"].ToString();
            }
            DataList read = (DataList)e.Item.FindControl("DataList2");
            read.DataSource = dv;
            read.DataBind();
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fanhgye

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值