<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Cascade_DataLists.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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="rptParent" runat="server">
<HeaderTemplate>
Province Region of China
</HeaderTemplate>
<ItemTemplate>
<fieldset style="width: 300px; margin-top: 15px">
<legend>
<%#Eval("Region") %></legend>
<asp:Repeater runat="server" DataSource='<%# ((System.Data.DataRowView)Container.DataItem).CreateChildView("subProvince") %>'>
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<%#Eval("Province") %>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</fieldset>
</ItemTemplate>
<FooterTemplate>
Taiwan is not included
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Cascade_DataLists
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = new DataSet();
ds.Tables.Add(getRegions());
ds.Tables.Add(getAllProvince());
ds.Tables[0].ChildRelations.Add(new DataRelation("subProvince", ds.Tables[0].Columns[0], ds.Tables[1].Columns[0], false));
rptParent.DataSource = ds.Tables[0].DefaultView;
rptParent.DataBind();
}
}
private DataTable getAllProvince()
{
DataTable dt = new DataTable("AllProvince");
dt.Columns.Add(new DataColumn("Region", typeof(string)));
dt.Columns.Add(new DataColumn("Province", typeof(string)));
dt.PrimaryKey = new DataColumn[] { dt.Columns[1] };
DataRow dr;
#region fill the table
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华东";
dr["Province"] = "上海";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华东";
dr["Province"] = "江苏";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华东";
dr["Province"] = "江西";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华东";
dr["Province"] = "安徽";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华东";
dr["Province"] = "山东";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华东";
dr["Province"] = "浙江";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华东";
dr["Province"] = "福建";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华南";
dr["Province"] = "广东";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华南";
dr["Province"] = "湖南";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华南";
dr["Province"] = "广西";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华南";
dr["Province"] = "海南";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华北";
dr["Province"] = "北京";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华北";
dr["Province"] = "天津";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华北";
dr["Province"] = "河北";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华北";
dr["Province"] = "河南";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华北";
dr["Province"] = "山西";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华中";
dr["Province"] = "湖北";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "西北";
dr["Province"] = "新疆";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "西北";
dr["Province"] = "甘肃";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "西北";
dr["Province"] = "宁夏";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "西北";
dr["Province"] = "陕西";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "东北";
dr["Province"] = "黑龙江";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "东北";
dr["Province"] = "吉林";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "东北";
dr["Province"] = "辽宁";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "西南";
dr["Province"] = "云南";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "西南";
dr["Province"] = "西藏";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "西南";
dr["Province"] = "贵州";
dr.EndEdit();
dt.Rows.Add(dr);
#endregion
return dt;
}
private DataTable getRegions()
{
DataTable dt = new DataTable("Regions");
dt.Columns.Add(new DataColumn("Region", typeof(string)));
dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };
DataRow dr;
#region fill the table
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华东";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华南";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华中";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "华北";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "东北";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "西北";
dr.EndEdit();
dt.Rows.Add(dr);
dr = dt.NewRow();
dr.BeginEdit();
dr["Region"] = "西南";
dr.EndEdit();
dt.Rows.Add(dr);
#endregion
return dt;
}
}
}