书籍父类别和子类别的显示
来源:互联网 发布:比价软件怎么用 编辑:程序博客网 时间:2024/05/20 05:23
原理:前台两个 DataList 的嵌套
<!-- 放置DataList数据控件 -->
<asp:DataList ID="ParentCaption" runat="server" RepeatDirection="Vertical" onitemdatabound="ParentCaption_ItemDataBound">
<ItemTemplate>
<div style=" height:20px; width:185px; background-color:#f0f0f0;font-weight:bold; ">
[ <%# Eval("Type_Name")%> ]
</div>
<!-- 子标题 -->
<asp:DataList ID="SonCaption" runat="server" RepeatDirection="Horizontal" RepeatColumns="2">
<ItemTemplate>
<div style="margin-left:20px; list-style-type:none;">
<a href='<%# "SortBooks.aspx?TypeID="+Eval("Type_ID") %> '>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Type_Name")%> '></asp:Label> </a>
</div>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
<!-- 放置DataList数据控件 -->
后台对两个 DataList 进行绑定:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindParentType();
}
}
private void bindParentType()
{
DataSet ds = new DataSet();
if (this.Cache["Type_Name"] == null)
{
BLL.BookCategory bookType = new BLL.BookCategory();
ds = bookType.GetList("");
this.Cache.Insert("Type_Name", ds, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
}
else
{
ds = (DataSet)this.Cache["Type_Name"];
}
DataRow[] darow = ds.Tables[0].Select(" Type_FatherTypeID is null");
DataTable dt = ds.Tables[0].Clone();
foreach (DataRow dr in darow)
{
dt.ImportRow(dr);
}
this.ParentCaption.DataSource = dt;
this.ParentCaption.DataKeyField = "Type_ID";
this.ParentCaption.DataBind();
}
//在父级 DataList 内找子级 DataList 控件
protected void ParentCaption_ItemDataBound(object sender, DataListItemEventArgs e)
{
DataList dl2 = (DataList)e.Item.FindControl("SonCaption");
int parentID = Convert.ToInt32(this.ParentCaption.DataKeys[e.Item.ItemIndex].ToString());
DataSet ds = (DataSet)this.Cache["Type_Name"];
DataRow[] dro = ds.Tables[0].Select(" Type_FatherTypeID=" + parentID);
DataTable dt = ds.Tables[0].Clone();
foreach (DataRow dr in dro)
{
dt.ImportRow(dr);
}
dl2.DataSource = dt;
dl2.DataBind();
}
- 书籍父类别和子类别的显示
- 实现父类别,子类别
- 多条件组合查询,并根据指定类别找出所有最小子类别的SQL语句备忘
- 关于网站主栏目多类别(或多子类)下的数据的准确显示
- 分层显示类别层次
- 分层显示类别层次
- 显示规格类别
- CMFCRibbonBar 类别 显示 隐藏
- UITableViewCell 显示类别
- static、子类和父类
- JAVA父类和子类
- java 父类和子类
- 三十七、类别 和 协议(一)类别
- 电子类经典书籍汇总(转 )
- 2.类别和扩展
- 特性和类别
- 类别和协议
- ios 类别和扩展
- 前台从数据库获取的字段在后台截取字符串
- Orx 1.2版本前瞻 附带iarwain对SFML以及SDL的评价
- 前台调用WebServices的方法
- 求高手指点下。。。O(∩_∩)O~
- 首页自动更换图片(类似flash)
- 书籍父类别和子类别的显示
- 一带输出参数存储过程的完整操作
- 访问Access2007的封装类DbAccess
- 连接access2007和2003的字符串
- ASP.NET调用存储过程返回值 输入输出参数
- 存储过程嵌套事物
- 订单号的生成方法
- 服务器更新
- Response.Buffer = True