addnews.aspx:
1
<%@ Register TagPrefix="ftb" Namespace="FreeTextBoxControls" Assembly="FreeTextBox" %>
2
<%@ Page language="c#" Codebehind="addnews.aspx.cs" AutoEventWireup="false" Inherits="dds2k.admin.addnews" %>
3
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
4
<HTML>
5
<HEAD>
6
<title>addnews</title>
7
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
8
<meta content="C#" name="CODE_LANGUAGE">
9
<meta content="JavaScript" name="vs_defaultClientScript">
10
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
11
<LINK href="../css/style2.css" type="text/css" rel="stylesheet">
12
</HEAD>
13
<body MS_POSITIONING="GridLayout">
14
<form id="addnews" method="post" runat="server">
15
<table cellSpacing="0" cellPadding="0" width="80%">
16
<tr>
17
<td height="20"></td>
18
</tr>
19
</table>
20
<TABLE style="BORDER-RIGHT: #999999 1px solid; BORDER-TOP: #999999 1px solid; BORDER-LEFT: #999999 1px solid; BORDER-BOTTOM: #999999 1px solid" cellSpacing="0" cellPadding="0" width="90%" align="center" bgColor="#ffffff" border="0">
21
<TBODY>
22
<TR>
23
<TD class="td_title" colSpan="2" height="25"><B>添加新闻</B></TD>
24
</TR>
25
<TR>
26
<TD class="content" align="middle" width="80" height="35">新闻类别:</TD>
27
<TD><asp:dropdownlist id="NewsKindList" Runat="server" Width="100" AutoPostBack="True"></asp:dropdownlist></TD>
28
</TR>
29
<TR>
30
<TD class="content" align="middle" height="35">新闻标题:</TD>
31
<TD><asp:textbox id="NewsTitle" Runat="server" MaxLength="200" width="98%" CssClass="input"></asp:textbox></TD>
32
</TR>
33
<TR>
34
<TD class="content" vAlign="top" align="middle">新闻内容:</TD>
35
<TD><FTB:FREETEXTBOX ID="FreeTextBox1" runat="server" ToolbarStyleConfiguration="OfficeXP" Width="98%"></FTB:FREETEXTBOX></TD>
36
</TR>
37
<TR>
38
<TD align="middle" colSpan="2"><BR>
39
<asp:button id="AddSumbit" Runat="Server" Text="添 加"></asp:button><BR>
40
<BR>
41
</TD>
42
</TR>
43
</TBODY>
44
</TABLE>
45
</form>
46
</TR></TBODY></TABLE></FORM>
47
</body>
48
</HTML>
49

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

addnews.aspx.cs:
1
using System;
2
using System.Collections;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Web;
7
using System.Web.SessionState;
8
using System.Web.UI;
9
using System.Web.UI.WebControls;
10
using System.Web.UI.HtmlControls;
11
using System.Data.SqlClient;
12
13
namespace dds2k.admin
14

{
15
/**//// <summary>
16
/// addnews 的摘要说明。
17
/// </summary>
18
public class addnews : System.Web.UI.Page
19
{
20
protected System.Web.UI.WebControls.TextBox NewsTitle;
21
protected System.Web.UI.WebControls.Button AddSumbit;
22
protected System.Web.UI.WebControls.DropDownList NewsKindList;
23
24
private void Page_Load(object sender, System.EventArgs e)
25
{
26
if(!Page.IsPostBack)
27
{
28
BindNewsKindData();
29
}
30
}
31
32
private void BindNewsKindData()
33
{ /**////清空DropDownList中的老数据
34
NewsKindList.Items.Clear();
35
/**////从数据库获取DDS_Newskind表的数据
36
SqlConnection myConnection = new SqlConnection(DataBaseDB.ConnectionString);
37
/**////定义向数据库NewsKinds表选择新闻种类的SQL语句
38
String cmdText =" SELECT * FROM DDS_NewsKinds ";
39
SqlDataAdapter myAdapter = new SqlDataAdapter(cmdText,myConnection);
40
myConnection.Open();
41
DataSet ds = new DataSet();
42
myAdapter.Fill(ds,"DDS_NewsKinds");
43
/**////设定DorpListBox控件的数据源,并且设定Text和Value属性
44
NewsKindList.DataSource = ds;
45
NewsKindList.DataTextField = "NewsKindName";
46
NewsKindList.DataValueField = "NewsKindID";
47
NewsKindList.DataBind();
48
myConnection.Close();
49
}
50
51
private void AddSumbit_Click(object sender,System.EventArgs e)
52
{
53
if(NewsTitle.Text.Trim().Length > 0)
54
{
55
SqlConnection myConnection = new SqlConnection(DataBaseDB.ConnectionString);
56
String cmdText = "INSERT INTO DDS_News (NewsTitle,NewsBody,NewsPubdate,NewsKindID) VALUES ('"
57
+ NewsTitle.Text +"','"+ FreeTextBox1.Text +"',GetDate(),'"+ Convert.ToInt32(NewsKindList.SelectedIndex) +"') ";
58
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
59
myConnection.Open();
60
myCommand.ExecuteNonQuery();
61
myConnection.Close();
62
Response.Write("<script>alert(\"添加新闻成功!\")</script>");
63
Response.Redirect("NewsManages.aspx");
64
}
65
else
66
{
67
Response.Write("<script>alert(\"新闻的标题不能为空\")</script>");
68
}
69
}
70
71
Web Form Designer generated code#region Web Form Designer generated code
72
override protected void OnInit(EventArgs e)
73
{
74
//
75
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
76
//
77
InitializeComponent();
78
base.OnInit(e);
79
}
80
81
/**//// <summary>
82
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
83
/// 此方法的内容。
84
/// </summary>
85
private void InitializeComponent()
86
{
87
this.AddSumbit.Click += new System.EventHandler(this.AddSumbit_Click);
88
this.Load += new System.EventHandler(this.Page_Load);
89
90
}
91
#endregion
92
}
93
}
94

2

3

4

5

6

7

8

9

10

11

12

13

14



15


16

17

18

19



20

21

22

23

24

25



26

27



28

29

30

31

32

33



34

35


36

37


38

39

40

41

42

43


44

45

46

47

48

49

50

51

52



53

54



55

56

57

58

59

60

61

62

63

64

65

66



67

68

69

70

71


72

73



74

75

76

77

78

79

80

81


82

83

84

85

86



87

88

89

90

91

92

93

94
