⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addnews.aspx.cs

📁 一个可以简单实现模块的拖曳、锁定、最大化、最小化控制的示例
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
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.Text;

public partial class AddNews : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!IsPostBack) {
			DataBindType();
		}
    }
//5_1_a_s_p_x.c_o_m

	private void DataBindType() {
		SqlHelp help=new SqlHelp();
		DataSet ds = help.GetList("Select * from Type");

		ddlType.DataSource = ds.Tables["ds"].DefaultView;
		ddlType.DataTextField = "TypeName";
		ddlType.DataValueField = "TypeId";
		ddlType.DataBind();
		ddlType.Items.Insert(0, new ListItem("--请选择--", "-1"));
	}
	protected void btnSave_Click(object sender, EventArgs e) {
		if (ddlType.SelectedIndex > 0 && txtCaption.Text != string.Empty && txtContent.Text != string.Empty) {
			int typeId = int.Parse(ddlType.SelectedValue);
			string caption = txtCaption.Text;
			string content = txtContent.Text;

			string strSql = "Insert into News(TypeId,NewsCaption,NewsContent) values(@TypeId,@NewsCaption,@NewsContent)";
			SqlParameter[] paras ={
				new SqlParameter("@TypeId",SqlDbType.Int),
				new SqlParameter("@NewsCaption",SqlDbType.NVarChar,200),
				new SqlParameter("@NewsContent",SqlDbType.NText)
			};
			paras[0].Value = typeId;
			paras[1].Value = caption;
			paras[2].Value = content;

			int rows = new SqlHelp().ExecuteNonQuery(strSql, paras);
			if (rows == 1) {
				PageHelp.ShowMessage(this.Page, "添加新闻成功!");
				btnReset_Click(null, null);
			} else {
				PageHelp.ShowMessage(this.Page, "添加新闻失败!");
			}
		} else {
			PageHelp.ShowMessage(this.Page, "必填项不能为空!");
			return;
		}
	}
	protected void btnReset_Click(object sender, EventArgs e) {
		ddlType.SelectedIndex = 0;
		txtCaption.Text = string.Empty;
		txtContent.Text = string.Empty;
	}
}

⌨️ 快捷键说明

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