addnewsinfo.aspx.cs

来自「一个简单的新闻后台管理系统」· CS 代码 · 共 68 行

CS
68
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 NewsManage_AddNewsInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //将新闻发布日期设置为系统当前日期
           this.TxtNEWSDATE.Text = DateTime.Now.ToShortDateString();

        }
    }

    protected void BtnAdd_Click(object sender, EventArgs e)
    {
        //建立连接
        SqlConnection con = DataAccess.CreateConnection();
        string sqlselect = "insert into t_News (NEWSTITLE,CLASSID,NEWSDATE,NEWSKEY,NEWSOURCE,NEWSCOUNENT,USERID) values ('" + this.TxtNEWSTITLE.Text + "','" + this.DroCLASSID.SelectedValue + "','" + this.TxtNEWSDATE.Text + "','" + this.TxtNEWSKEY.Text + "','" + this.TxtNEWSOURCE.Text + "','" + this.FreeTextBox1.Text + "','" + this.DropDownList1.SelectedValue.ToString() + "')";
        SqlCommand comm = new SqlCommand();
        comm.Connection = con;
        comm.CommandText = sqlselect;
        try
        {
            comm.Connection.Open();
            comm.ExecuteNonQuery();
            Response.Write("<script>window.alert('添加成功')</script>");

        }

        finally
        {
            con.Close();
            //Response.Write("<script>window.alert('添加有误请重新添加!')</script>");

        }
        //将所有文本框的值设置为空

        this.TxtNEWSKEY.Text = "";
        this.TxtNEWSOURCE.Text = "";
        this.TxtNEWSTITLE.Text = "";

        this.FreeTextBox1.Text = "";
    }
    protected void BtnEsc_Click(object sender, EventArgs e)
    {
       
    }
    protected void TextBox3_TextChanged(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?