DataList嵌套DataList

來源:互聯網
上載者:User
DataList嵌套DataList


1.html代碼<HTML>
    <HEAD>
        <title>NestedDataLists</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://singlepine.cnblogs.com/">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <asp:DataList runat="server" Id="dlCategories" GridLines="Both" Bordercolor="black" cellpadding="3"
                cellspacing="0" Headerstyle-BackColor="#DDDDDD" Headerstyle-Forecolor="#777777" Headerstyle-Font-Name="Arial"
                Headerstyle-Font-Size="14" Headerstyle-Font-Bold="true" Font-Name="Arial" Font-Bold="true"
                Font-Italic="true" Font-Size="11" ForeColor="Red" RepeatColumns="1">
                <HeaderTemplate>
                    省市 & 市區
                </HeaderTemplate>
                <ItemTemplate>
                    <%# DataBinder.Eval(Container, "DataItem.province") %>
                    <br>
                    <asp:DataList runat="server" Id="ChildDataList" GridLines="None" Bordercolor="black" cellpadding="3" cellspacing="0" Headerstyle-BackColor="#8080C0" Headerstyle-Font-Name="Arial" Headerstyle-Font-Size="8" Font-Name="Arial" Font-Size="8" datasource='<%# DataBinder.Eval(Container, "DataItem.myrelation") %>' RepeatColumns="5">
                        <ItemTemplate>
                            &nbsp; &nbsp;
                            <%# DataBinder.Eval(Container, "DataItem.city") %>
                        </ItemTemplate>
                    </asp:DataList>
                </ItemTemplate>
            </asp:DataList>
        </form>
    </body>
</HTML>

2.cs代碼public class NestedDataLists : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.DataList dlCategories;
    
        private void Page_Load(object sender, System.EventArgs e)
        {
            string constring=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
            
            DataSet ds=new DataSet();
            string sql1="select * from province";
            SqlDataAdapter    sda1 =new SqlDataAdapter(sql1,constring);
            sda1.Fill(ds,"province");

            string sql2="select * from city";
            SqlDataAdapter    sda2 =new SqlDataAdapter(sql2,constring);
            sda2.Fill(ds,"city");
            
            ds.Relations.Add("myrelation", ds.Tables["province"].Columns["provinceID"], ds.Tables["city"].Columns["father"]);
            dlCategories.DataSource=ds.Tables["province"].DefaultView;
            dlCategories.DataBind();
        }
        
        Web Form Designer generated code#region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /**//// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {    
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
    }

轉載:http://www.cnblogs.com/jembai/articles/1290660.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.