?? addnews.aspx.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 + -