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对应!
查看全文
相关阅读:
git 命令
Spring Boot Web应用开发 CORS 跨域请求支持
layui demo
jQuery jqGrid 4.7
jQurey zTree Demo 3.5
jQurey zTree API 3.5
jQurey Select2 4.0
jQurey Validation 1.16
Laytpl 1.2
My97DatePicker 4.8
原文地址:https://www.cnblogs.com/jiangyuxuan/p/843486.html
最新文章
POJ 1815 Friendship ★(字典序最小点割集)
POJ 1815 Friendship ★(字典序最小点割集)
最小割的一些性质
最小割的一些性质
SPOJ-OPTM Optimal Marks ★★(按位建图 && 最小割)
SPOJ-OPTM Optimal Marks ★★(按位建图 && 最小割)
ZOJ 2676 Network Wars ★(最小割算法介绍 && 01分数规划)
ZOJ 2676 Network Wars ★(最小割算法介绍 && 01分数规划)
POJ 2728 Desert King ★(01分数规划介绍 && 应用の最优比率生成树)
POJ 2728 Desert King ★(01分数规划介绍 && 应用の最优比率生成树)
热门文章
bnuoj24252 Divide
poj2763 Housewife Wind
fzu2202 犯罪嫌疑人
hdu5497 Inversion
hdu5496 Beauty of Sequence
UVALive 7146
hdu5489 Removed Interval
hdu4521 小明系列问题——小明序列
hdu5491 The Next
poj1180 Batch Scheduling
Copyright © 2011-2022 走看看