runxinzhi.com
首页
百度搜索
用Repeater控件显示主从关系数据表
TOP.ASPX
<%@ Page Debug="true" language="c#" Codebehind="Top.aspx.cs" Inherits="QA.Top" %>
1
<%
@ Page Debug
=
"
true
"
language
=
"
c#
"
Codebehind
=
"
Top.aspx.cs
"
Inherits
=
"
QA.Top
"
%>
2
3
<
HTML
>
4
<
HEAD
>
5
<
title
>
Top
</
title
>
6
<
meta name
=
"
CODE_LANGUAGE
"
Content
=
"
C#
"
>
7
</
HEAD
>
8
<
body
>
9
<
form id
=
"
Form1
"
method
=
"
post
"
runat
=
"
server
"
>
10
<
asp:repeater ID
=
"
Class
"
runat
=
"
server
"
OnItemCreated
=
"
Class_ItemCreated
"
>
11
<
itemtemplate
>
<
br
><
b
><%
# DataBinder.Eval(Container.DataItem,
"
ClassName
"
)
%>
:
</
b
>
12
<
asp:repeater ID
=
"
Forum
"
runat
=
"
server
"
>
13
<
itemtemplate
><%
# DataBinder.Eval(Container.DataItem,
"
ClassName
"
)
%>
14
</
itemtemplate
>
15
</
asp:repeater
>
16
</
itemtemplate
>
17
</
asp:repeater
>
18
</
form
>
19
</
body
>
20
</
HTML
>
21
Top.aspx.cs
1
using
System;
2
using
System.Configuration;
3
using
System.Data;
4
using
System.Data.OleDb;
5
using
System.Text;
6
using
System.Web;
7
using
System.Web.UI;
8
using
System.Web.UI.WebControls;
9
using
System.Web.UI.HtmlControls;
10
11
namespace
QA
12
{
13
/**/
///
<summary>
14
///
Top 的摘要说明。
15
///
</summary>
16
public
class
Top : System.Web.UI.Page
17
{
18
/**/
///
<summary>
19
///
数据库连接
20
///
</summary>
21
22
public
static
string
strConn
23
{
24
get
25
{
26
StringBuilder strResult
=
new
StringBuilder(ConfigurationSettings.AppSettings[
"
Provider
"
]);
27
strResult.Append(
"
;
"
);
28
strResult.Append(
"
Data Source =
"
);
29
strResult.Append(HttpContext.Current.Server.MapPath(
"
.
"
));
30
strResult.Append(
"
\\
"
);
31
strResult.Append(ConfigurationSettings.AppSettings[
"
DataSource
"
]);
32
return
strResult.ToString();
33
}
34
}
35
protected
string
strSQL;
36
protected
OleDbDataAdapter Adpt
=
new
OleDbDataAdapter();
37
protected
DataSet Ds
=
new
DataSet();
38
protected
OleDbConnection Conn
=
new
OleDbConnection(strConn);
39
protected
Repeater Class
=
new
Repeater();
40
protected
OleDbCommand Cmd
=
new
OleDbCommand();
41
42
private
void
Page_Load(
object
sender, System.EventArgs e)
43
{
44
if
(
!
Page.IsPostBack)
45
{
46
strSQL
=
"
SELECT * FROM Qclass WHERE Dclass = 0
"
;
47
Adpt
=
new
OleDbDataAdapter(strSQL, Conn);
48
Adpt.Fill(Ds,
"
Class
"
);
49
Class.DataSource
=
Ds.Tables[
"
Class
"
].DefaultView;
50
Class.DataBind();
51
}
52
53
}
54
protected
DataTable Forum_Source(
int
id)
55
{
56
if
(Ds.Tables.Contains(
"
Forum
"
)
&&
Ds.Tables.CanRemove(Ds.Tables[
"
Forum
"
]))
57
Ds.Tables.Remove(
"
Forum
"
);
58
strSQL
=
"
SELECT * FROM Qclass WHERE Dclass = @id
"
;
59
Cmd
=
new
OleDbCommand(strSQL, Conn);
60
Cmd.Parameters.Add(
new
OleDbParameter(
"
@id
"
, OleDbType.Integer)).Value
=
id;
61
Adpt
=
new
OleDbDataAdapter(Cmd);
62
Adpt.Fill(Ds,
"
Forum
"
);
63
return
Ds.Tables[
"
Forum
"
];
64
}
65
//
控件调用的OnItemCreated类
66
protected
void
Class_ItemCreated(
object
sender, RepeaterItemEventArgs e)
67
{
68
((Repeater)e.Item.FindControl(
"
Forum
"
)).DataSource
=
Forum_Source(
int
.Parse(((System.Data.DataRowView)e.Item.DataItem)[
"
id
"
].ToString())).DefaultView;
69
}
70
71
}
72
}
73
<%# DataBinder.Eval(Container.DataItem, "ClassName") %>
数据库表如下:
当Dclass为0时,此分类为主分类,当Dclass不为0时为小分类,并与主分类ID对应!
相关阅读:
normalize.css 中文版
[转载]自适应高度输入框
【转载】H5页面列表的无线滚动加载(前端分页)
CSS设置table下tbody滚动条与thead对齐的方法
[转载]Jquery mobiscroll 移动设备(手机)wap日期时间选择插件以及滑动、滚动插件
wordpress 目录、数据结构和解析原理
WordPress基础知识:条件判断标签及用法大全
主题如何添加tag标签页面
WordPress进阶:[2]不同页面显示不同的侧边栏
WordPress进阶:[1]怎样用tag标签做导航菜单
原文地址:https://www.cnblogs.com/jiangyuxuan/p/843486.html
最新文章
各大搜索引擎网站收录提交入口
实时股票数据接口大全
IOS UIApplicationMain函数
iOS程序的启动过程介绍
搭建Mac OS X下cocos2d-x的Android开发环境
Mac OS X下搭建Android开发环境(包括SDK和NDK)
项目笔记:2018年4月(SpringCloud架构和SpringBoot框架)
看书笔记:大型网站技术架构
项目笔记:2017年(SSM架构)
select、poll、epoll源码分析
热门文章
linux命令-netstat
linux命令-ps
剑指offer-2.单例模式
剑指offer-1.赋值元素运算符函数
设计模式-建造者模式(创建型)
设计模式-观察者模式(行为)、发布订阅模式
设计模式-桥接模式(结构型)、享元模式(结构型)
协程
leetcode 29. Divide Two Integers
通用代码2
Copyright © 2020-2023
润新知