当涂电脑培训——万飞科技——CMS开发:发布新闻

来源:互联网 发布:情绪管理 知乎 编辑:程序博客网 时间:2024/06/02 17:33

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient; //SQL Serve数据库命名空间

public partial class admin_News_add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //数据库连接字符串
        string ConStr = "server=(local);user id=sa;pwd=netoffice;database=wf_data";
        SqlConnection conn = new SqlConnection(ConStr);
        conn.Open();
        //执行查询语句加载DropDownList相关数据
        string SqlStr = "select * from news_type";
        //SqlDataAdapter ada = new SqlDataAdapter(SqlStr, conn);
        SqlCommand myCommand = new SqlCommand(SqlStr, conn);
        SqlDataReader myReader = myCommand.ExecuteReader();
        while (myReader.Read())
        {
            typeid.Items.Add(new ListItem(myReader["cType"].ToString(), myReader["typeid"].ToString()));
        }
        _Date.Text = DateTime.Now.ToString();
        conn.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string ConStr = "server=(local);user id=sa;pwd=netoffice;database=wf_data";
        SqlConnection conn = new SqlConnection(ConStr);
        conn.Open();
        //添加数据
        string SqlStr = "insert into news_list(title,_edit,type_id,_memo,_user) values('" + Title.Text + "','" + _Edit.Value.Replace("/n/r", "<br>") + "','" + typeid.Text + "','" + _memo.Text + "','" + _User.Text + "')";
        SqlCommand com = new SqlCommand(SqlStr,conn);
        com.ExecuteNonQuery();
        conn.Close();
    }
}

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="News_add.aspx.cs" Inherits="admin_News_add" %>

<%@ Register assembly="FredCK.FCKeditorV2" namespace="FredCK.FCKeditorV2" tagprefix="FCKeditorV2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <table class="style1">
            <tr>
                <td>
                    标题:<asp:TextBox ID="Title" runat="server" Width="525px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    分类:<asp:DropDownList ID="typeid" runat="server">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    <FCKeditorV2:FCKeditor ID="_Edit" runat="server" Height="400px">
                    </FCKeditorV2:FCKeditor>
                </td>
            </tr>
            <tr>
                <td>
                    备注:<asp:TextBox ID="_memo" runat="server" Height="78px" TextMode="MultiLine"
                        Width="100%"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    日期:<asp:TextBox ID="_Date" runat="server"></asp:TextBox>
                    发布人:<asp:TextBox ID="_User" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td style="text-align: center">
                    <asp:Button ID="Button1" runat="server" Text="发布信息" onclick="Button1_Click" />
                    </td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>

www.dtwfkj.com