DataList嵌套式导航

界面:
<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>
界面代码:
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();
        }
    }
数据层:
using System;
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
    {
//首页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;
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值