界面:
<asp:DataList ID="DL_Cate" runat="server" Width="100%" OnItemCommand="DL_Cate_ItemCommand">
<SelectedItemTemplate>
<asp:DataList ID="DL_SCate" runat="server" Width="100%" DataSource='<%#((System.Data.DataRowView)Container.DataItem).CreateChildView("SmallCateView") %>'>
<ItemTemplate>
<asp:LinkButton ID="SCate" runat="server" Text='<%# Eval("SC_Name")%>' BackColor="#F1F0EE"
PostBackUrl='<%# Eval("SC_ID","~/CateDetails.aspx?SID={0}") %>' Font-Size="Small"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</SelectedItemTemplate>
<ItemTemplate>
<asp:LinkButton Font-Underline="false" ForeColor="#003399" ID="Cate" runat="server"
Text='<%# "* "+Eval("CateName")%>' CommandName="select"
CommandArgument='<%# Eval("CateID") %>' Font-Size="XX-Large" Font-Bold="true"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
<SelectedItemTemplate>
<asp:DataList ID="DL_SCate" runat="server" Width="100%" DataSource='<%#((System.Data.DataRowView)Container.DataItem).CreateChildView("SmallCateView") %>'>
<ItemTemplate>
<asp:LinkButton ID="SCate" runat="server" Text='<%# Eval("SC_Name")%>' BackColor="#F1F0EE"
PostBackUrl='<%# Eval("SC_ID","~/CateDetails.aspx?SID={0}") %>' Font-Size="Small"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</SelectedItemTemplate>
<ItemTemplate>
<asp:LinkButton Font-Underline="false" ForeColor="#003399" ID="Cate" runat="server"
Text='<%# "* "+Eval("CateName")%>' CommandName="select"
CommandArgument='<%# Eval("CateID") %>' Font-Size="XX-Large" Font-Bold="true"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
界面代码:
protected void DL_Cate_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "select")
{
this.DL_Cate.SelectedIndex = e.Item.ItemIndex;
DL_Cate.DataSource = p_access.GetReView().Tables[0].DefaultView;
DL_Cate.DataBind();
}
}
{
if (e.CommandName == "select")
{
this.DL_Cate.SelectedIndex = e.Item.ItemIndex;
DL_Cate.DataSource = p_access.GetReView().Tables[0].DefaultView;
DL_Cate.DataBind();
}
}
数据层:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Web;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Web;
namespace DataAccess
{
public class DataAccess
{
{
public class DataAccess
{
//首页left
public DataSet GetReView()
{
string sql = "IndexCate";
da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
//设置数据集中两个表的名称
ds.Tables[0].TableName = "Cate";
ds.Tables[1].TableName = "SmallCate";
//父
DataColumn a = ds.Tables["Cate"].Columns["CateID"];
//子
DataColumn b = ds.Tables["SmallCate"].Columns["CateID"];
//创建关系对象
DataRelation drt = new DataRelation("SmallCateView", a, b, false);
//为dataset中的关系集合添加关系对象
ds.Relations.Add(drt);
return ds;
}
}
}
本文出自 51CTO.COM技术博客
public DataSet GetReView()
{
string sql = "IndexCate";
da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
//设置数据集中两个表的名称
ds.Tables[0].TableName = "Cate";
ds.Tables[1].TableName = "SmallCate";
//父
DataColumn a = ds.Tables["Cate"].Columns["CateID"];
//子
DataColumn b = ds.Tables["SmallCate"].Columns["CateID"];
//创建关系对象
DataRelation drt = new DataRelation("SmallCateView", a, b, false);
//为dataset中的关系集合添加关系对象
ds.Relations.Add(drt);
return ds;
}
}
}