zoukankan
html css js c++ java
用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对应!
查看全文
相关阅读:
(5.1.4)引擎管理——SSMS管理使用小技巧
(5.1.3)引擎管理——恢复系统数据库
Kafka 基本原理
读懂基础机器学习算法
数据挖掘常用工具
Oracle 增加修改删除字段
.net中使用ODP.net访问Oracle数据库(无客户端部署方法)
数据挖掘系列(1)关联规则挖掘基本概念与Aprior算法
ORACLE存储过程学习
js版扫雷(可直接运行试玩)
原文地址:https://www.cnblogs.com/jiangyuxuan/p/843486.html
最新文章
关于直播学习笔记-002-Red5 & Sewise Player & Wirecast
GIS-002-gdal2srtmtiles使用注意事项
GIS-001-gdal软件下载地址
MVC是一种用于表示层设计的复合设计模式
asp.net一些面试题(转)
马士兵感言 (转)
UML---UML中的几种关系(依赖,关联,泛化,实现)
一些面试题
C#基础概念二十五问
Session和几种状态保持方案理解
热门文章
高并发量网站解决方案
何为中间语言IL?
创业不是纸上谈兵,把你的商业计划扔进垃圾桶吧
(4.33)sql server2014内存数据库(内存中OLTP(In-Memory OLTP))
(2.2)【转】mysql的SQL笔记
【查阅】Mysql 常规运维命令
一些常用的字符串函数(CLR函数)
(4.15)mysql备份还原——物理备份之XtraBackup的下载与安装
【基本优化实践】【1.3】最大内存参数限制
(5.1.5)引擎管理——多服务器管理之中央管理服务器(CMS)
Copyright © 2011-2022 走看看