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对应!
查看全文
相关阅读:
Java线程池
代理模式
Bean的加载
Spring的启动流程
MFC编程入门之二十七(常用控件:图片控件PictureControl)
MFC编程入门之二十六(常用控件:滚动条控件ScrollBar)
MFC编程入门之二十五(常用控件:组合框控件ComboBox)
MFC编程入门之二十四(常用控件:列表框控件ListBox)
MFC编程入门之二十三(常用控件:按钮控件的编程实例)
MFC编程入门之二十二(常用控件:按钮控件Button、Radio Button和Check Box)
原文地址:https://www.cnblogs.com/jiangyuxuan/p/843486.html
最新文章
WINFORM--第二讲(窗体)
WINFORM--第一讲
使用命令参数
数据访问---ADO.NET
<面向对象>--多态
sqoop从mysql导入到hdfs出现乱码问题
centos7.x86_64搭建饥荒服务器
利用hive源码解析sql查了哪些表哪些字段
Hive-jdbc获取sessionId
root用户无法切换到cdh的hive账号上
热门文章
对jvm进行gc的时间、数量、jvm停顿时间的监控
安装spark问题汇总
linux在终端输入中文乱码
hbase报错Could not initialize class org.apache.hadoop.hbase.protobuf.ProtobufUtil
gpdb删除segment上残余的session和sql
JDK1.7 HashMap死循环问题
大型网站架构演化
Synchronized && Lock
死锁
Java Bug--官方编号为 6260652
Copyright © 2011-2022 走看看