📄 editnews.aspx.cs
字号:
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.OleDb;
public partial class admin_EditNews : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["adminAccount"] != null)
{
if (Session["adminAccount"] != "")
{
}
else
{
Response.Redirect("adminErr.aspx?errMsg=没有登陆或者登陆超时.<a href='adminlogin.aspx'>现在登陆</a>");
}
}
else
{
Response.Redirect("adminErr.aspx?errMsg=没有登陆或者登陆超时.<a href='adminlogin.aspx'>现在登陆</a>");
}
int newsId = Convert.ToInt32(Request.QueryString["NewsId"]);
string sql = "Select * from [NcNews] Where [NewsId]=" + newsId;
WebConfig.CreateCon();
OleDbDataAdapter da = new OleDbDataAdapter(sql, WebConfig.con);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
this.TextBox1.Text = dt.Rows[0]["NewsTitle"].ToString();
this.TextBox2.Text = dt.Rows[0]["NewsContent"].ToString();
string imgUrl = dt.Rows[0]["NewsPic"].ToString();
if (imgUrl == "")
imgUrl = "../images/no_pic.gif";
else
imgUrl = "../upload/" + imgUrl;
this.Image1.ImageUrl = imgUrl;
this.HiddenField2.Value = dt.Rows[0]["NewsId"].ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string ProductIntro = this.TextBox2.Text.Replace("'", "‘");
string picPath = "";
//定义一个变量,取全部文件名
string fileFullname = this.FileUpload1.FileName;
//取出当前日期
string dataName = DateTime.Now.ToString("yyyyMMddhhmmss");
//取文件扩展名
string fileName = fileFullname.Substring(fileFullname.LastIndexOf("\\") + 1);
//截取上传文件的扩展名既"."后面的字母所以+1
string type = fileFullname.Substring(fileFullname.LastIndexOf(".") + 1);
//类型控制,想上传什么类型,可以在这里类似添加
if (type == "jpg" || type == "gif" || type == "bmp")
{
this.FileUpload1.SaveAs(Server.MapPath("/upload") + "\\" + dataName + fileName);
picPath = dataName + fileName;
//image1输出上传图片,可以在这里控制图片大小
//this.Image1.ImageUrl = "../upload/" + picPath;
}
else
{
picPath = "";
}
string nameList = "";
string valueList = "";
if (picPath != "")
{
nameList = ", [NewsPic] ";
valueList = ",'" + picPath + "'";
}
string sql = "Update [NcNews] Set [NewsTitle]='" + this.TextBox1.Text + "',[NewsContent]='" + ProductIntro + "'";
if (picPath != "")
{
sql += ",[NewsPic]='" + picPath + "'";
}
sql +=" Where [NewsId]=" + Convert.ToInt32(this.HiddenField2.Value);
//Response.Write(sql);
WebConfig.CreateCon();
OleDbCommand cmd = new OleDbCommand(sql, WebConfig.con);
cmd.ExecuteNonQuery();
Response.Redirect("adminErr.aspx?errMsg=修改成功!<a href='EditNews.aspx?NewsId=" + Convert.ToInt32(this.HiddenField2.Value) + "'>返回</a>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -