Datalist巢狀

yyldir發表於2008-09-10

前臺程式碼

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="dDataList.aspx.cs" Inherits="movie_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>無標題頁</title>
    <link href="../CSS/CSS.css" rel="stylesheet" type="text/css" />
    <link href="../CSS/play.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .style1
        {
            width: 89px;
        }
        .style2
        {
            width: 97px;
        }
    </style>
</head>
<body>
    <form id="form1">
    <div style="text-align: left">   
        <asp:DataList ID="DataList1" runat="server"
            onitemdatabound="DataList1_ItemDataBound">
            <ItemTemplate>
                <div style="height: 158px; width: 939px;">
                    <table style="width:101%; height: 154px;">
                        <tr>
                            <td class="style1" rowspan="4">
                                <a href='<%# "listmovie.aspx?id="+Eval("mid")%>'><img alt="" src="<%#Eval("image") %>"
                                    style="height: 150px; width: 120px" /></a><td class="style2">
                                名稱:<asp:Label ID="Label4" runat="server" Text='<%# Eval("title") %>'></asp:Label>
                            </td>
                                <td rowspan="4">
                                <div class="abcs_2">
                                    <div class="movienews3c">
        <asp:DataList ID="dlsProductInfo" runat="server" RepeatColumns="6"
            RepeatDirection="Horizontal" Height="126px" Width="30px">
           
            <ItemTemplate>
                <asp:HyperLink ID="HyperLink1" runat="server"
                    NavigateUrl='<%# "play.aspx?id="+Eval("mid")+"&number="+Eval("number") %>'
                    Text='<%# "第"+Eval("number")+"集" %>'></asp:HyperLink>
            </ItemTemplate>
        </asp:DataList>
    </div>
    </div>
                                </td>
                        </tr>
                        <tr>
                            <td class="style2">
                                時間:<asp:Label ID="Label1" runat="server" Text='<%# Eval("datetime","{0:yyyy-MM-dd}") %>  '></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td class="style2">
                                型別:<asp:Label ID="Label3" runat="server" Text='<%# Eval("leixin") %>'></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td class="style2">
                                簡介:<asp:Label ID="Label5" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"jianjie").ToString().Length>15?DataBinder.Eval(Container.DataItem,"jianjie").ToString().Substring(0,15)+"...":DataBinder.Eval(Container.DataItem,"jianjie").ToString()  %>'></asp:Label>
                            </td>
                        </tr>
                    </table>
                </div>
            </ItemTemplate>
        </asp:DataList>
    </div>
    </form>
</body>
</html>

 

 

 後臺程式碼

 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class movie_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ComFunction cf = new ComFunction();
        DataSet ds = cf.DataBind("M_title");
        DataList1.DataSource = ds;
        DataList1.DataBind();
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataList dataList = (DataList)e.Item.FindControl("dlsProductInfo");
            DataRowView rowv = (DataRowView)e.Item.DataItem;
            string mainID = Convert.ToString(rowv["mid"]);

            if (mainID!="")
            {
                ComFunction cf = new ComFunction();
                DataSet ds = cf.BindOneField("M_dizhi", "mid", mainID);
                if (ds != null)
                {
                    try
                    {
                        dataList.DataSource = ds;
                        dataList.DataBind();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
    }
}

 

相關文章