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对应!
查看全文
相关阅读:
Mysql锁机制介绍
开启Mysql慢查询来优化mysql
开启mysql慢查询日志并使用mysqldumpslow命令查看
MySQL MyISAM/InnoDB高并发优化经验
UIPageControl
UIPikerView的属性
UIScrollView
UISement属性
UISlide属性
UISwitch
原文地址:https://www.cnblogs.com/jiangyuxuan/p/843486.html
最新文章
MMORPG大型游戏设计与开发(UI SYSTEM SHOW)
MMORPG大型游戏设计与开发(part6 of net)
MMORPG大型游戏设计与开发(part5 of net)
MMORPG大型游戏设计与开发(part4 of net)
MMORPG大型游戏设计与开发(part3 of net)
MMORPG大型游戏设计与开发(part2 of net)
MMORPG大型游戏设计与开发(part1 of net)
MMORPG大型游戏设计与开发(规范)
MMORPG大型游戏设计与开发(构架)
MMORPG大型游戏设计与开发(概述)updated
热门文章
Memcached 深度分析
Memcached应用总结
memcached +mysql+php 测试例子
Redis,MemCached,MongoDB 概述
Memcached 简介
linux free命令建检查内存状态
PHP生成随机字符串包括大小写字母
Mysql数据数据[字节、长度、数据范围]一览表
linux性能分析命令top
如何分析apache日志[access_log(访问日志)和error_log(错误日志)]
Copyright © 2011-2022 走看看