62,243
社区成员




/****** 对象: 数据库 record 脚本日期: 2009-12-17 11:36:45 ******/
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'record')
DROP DATABASE [record]
GO
CREATE DATABASE [record] ON (NAME = N'record_Data', FILENAME = N'E:\sql2000\MSSQL\Data\record_Data.MDF' , SIZE = 1, FILEGROWTH = 10%) LOG ON (NAME = N'record_Log', FILENAME = N'E:\sql2000\MSSQL\Data\record_Log.LDF' , SIZE = 1, FILEGROWTH = 10%)
COLLATE Chinese_PRC_CI_AS
GO
exec sp_dboption N'record', N'autoclose', N'false'
GO
exec sp_dboption N'record', N'bulkcopy', N'false'
GO
exec sp_dboption N'record', N'trunc. log', N'true'
GO
exec sp_dboption N'record', N'torn page detection', N'true'
GO
exec sp_dboption N'record', N'read only', N'false'
GO
exec sp_dboption N'record', N'dbo use', N'false'
GO
exec sp_dboption N'record', N'single', N'false'
GO
exec sp_dboption N'record', N'autoshrink', N'true'
GO
exec sp_dboption N'record', N'ANSI null default', N'false'
GO
exec sp_dboption N'record', N'recursive triggers', N'false'
GO
exec sp_dboption N'record', N'ANSI nulls', N'false'
GO
exec sp_dboption N'record', N'concat null yields null', N'false'
GO
exec sp_dboption N'record', N'cursor close on commit', N'false'
GO
exec sp_dboption N'record', N'default to local cursor', N'false'
GO
exec sp_dboption N'record', N'quoted identifier', N'false'
GO
exec sp_dboption N'record', N'ANSI warnings', N'false'
GO
exec sp_dboption N'record', N'auto create statistics', N'true'
GO
exec sp_dboption N'record', N'auto update statistics', N'true'
GO
if( (@@microsoftversion / power(2, 24) = 8) and (@@microsoftversion & 0xffff >= 724) )
exec sp_dboption N'record', N'db chaining', N'false'
GO
use [record]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_two_one]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[two] DROP CONSTRAINT FK_two_one
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_three_two]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[three] DROP CONSTRAINT FK_three_two
GO
/****** 对象: 表 [dbo].[one] 脚本日期: 2009-12-17 11:36:45 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[one]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[one]
GO
/****** 对象: 表 [dbo].[three] 脚本日期: 2009-12-17 11:36:45 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[three]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[three]
GO
/****** 对象: 表 [dbo].[two] 脚本日期: 2009-12-17 11:36:45 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[two]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[two]
GO
/****** 对象: 表 [dbo].[one] 脚本日期: 2009-12-17 11:36:47 ******/
CREATE TABLE [dbo].[one] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[title] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
/****** 对象: 表 [dbo].[three] 脚本日期: 2009-12-17 11:36:47 ******/
CREATE TABLE [dbo].[three] (
[trid] [int] IDENTITY (1, 1) NOT NULL ,
[twoid] [int] NULL ,
[trtitle] [ntext] COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** 对象: 表 [dbo].[two] 脚本日期: 2009-12-17 11:36:47 ******/
CREATE TABLE [dbo].[two] (
[tid] [int] IDENTITY (1, 1) NOT NULL ,
[oneid] [int] NULL ,
[ttitle] [ntext] COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bin();
}
}
//绑定第一级数据
private void bin()
{
string sql = "select * from one";
DataTable dt = select(sql);
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
protected void Repeater1_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rp = (Repeater)e.Item.FindControl("Repeater2");
Label lb1 = (Label)e.Item.FindControl("Label111");
string id=lb1.Text;
string sql="select * from two where oneid='"+id+"'";
DataTable dt=select(sql);
rp.DataSource =dt;
rp.DataBind();
}
}
protected void Repeater2_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rp = (Repeater)e.Item.FindControl("Repeater3");
Label lb1 = (Label)e.Item.FindControl("Label222");
string id = lb1.Text;
string sql = "select * from three where twoid='" + id + "'";
DataTable dt = select(sql);
rp.DataSource = dt;
rp.DataBind();
}
}
//回复
protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
}
//数据库连接
private SqlConnection getcon()
{
SqlConnection sqlcon = new SqlConnection("server=.;database=record;uid=sa;pwd=");
return sqlcon;
}
//查询返回datatable
private DataTable select(string sql)
{
using (SqlConnection sqlcon = getcon())
{
DataTable dt = new DataTable();
try
{
SqlDataAdapter da = new SqlDataAdapter(sql, sqlcon);
sqlcon.Open();
da.Fill(dt);
}
finally
{
sqlcon.Close();
}
return dt;
}
}
//插入,修改,删除
protected bool addupdatedelete(string sql)
{
using (SqlConnection sqlcon = getcon())
{
SqlCommand com = new SqlCommand(sql, sqlcon);
sqlcon.Open();
try
{
int k = com.ExecuteNonQuery();
if (k > 0)
{
return true;
}
}
finally
{
sqlcon.Close();
}
}
return false;
}
/// <summary>
/// 发表新话题
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
string text = TextBox1.Text;
string sql = "insert into one values('"+text+"')";
if (addupdatedelete(sql))
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "OK", "alert('添加成功!');", true);
}
else
{
ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "OK", "alert('添加失败!');", true);
}
bin();
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
li
{
list-style:none;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_OnItemDataBound">
<ItemTemplate>
<li> <asp:Label ID="Label2" runat="server" Text='<%# Eval("title") %>'></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("id") %>'
Text="回复" OnCommand="LinkButton1_Command"></asp:LinkButton>
<asp:Label ID="Label111" Visible="false" runat="server" Text='<%# Eval("id") %>'></asp:Label>
</li>
<li>
<ul>
<asp:Repeater ID="Repeater2" runat="server" OnItemDataBound="Repeater2_OnItemDataBound">
<ItemTemplate>
<li><asp:Label ID="Label2" runat="server" Text='<%#Eval("ttitle")%>'></asp:Label>
<asp:LinkButton ID="LinkButton2" CommandArgument='<%# Eval("tid") %>' runat="server">回复</asp:LinkButton>
<asp:Label ID="Label222" runat="server" Visible="false" Text='<%#Eval("tid")%>'></asp:Label>
</li>
<li>
<ul>
<asp:Repeater ID="Repeater3" runat="server">
<ItemTemplate>
<li>
<asp:Label ID="Label2" runat="server" Text='<%#Eval("trtitle")%>'></asp:Label>
<asp:LinkButton ID="LinkButton2" CommandArgument='<%# Eval("trid") %>' runat="server">回复</asp:LinkButton>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</li>
</ItemTemplate>
</asp:Repeater>
<br />
发表新话题:<br />
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Width="413px"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="发表" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>