温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:内文广告管理系统V1.1版源码
当前文件:
TextAd/admin1.aspx.cs,打开代码结构图
TextAd/admin1.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
public partial class admin1 : System.Web.UI.Page 12
{ 13
//该源 码下 载自www.51aspx.com(51aspx.com) 14
protected void Page_Load(object sender, EventArgs e) 15
{ 16
//没有登录,则转向登录 17
if (Session["admin"]==null||Session["admin"].ToString() != "true") Response.Redirect("login.aspx"); 18
if (!IsPostBack) 19
{ 20
myDataBind();//绑定数据 21
} 22
} 23
//分页 24
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 25
{ 26
GridView1.PageIndex = e.NewPageIndex; 27
myDataBind(); 28
} 29
//删除 30
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 31
{ 32
if (e.CommandName == "del") 33
{ 34
string id = e.CommandArgument.ToString(); 35
try 36
{ 37
Sql s = new Sql(); 38
s.ExecuteSql("delete from keyarray where id=" + id);//删除 39
myDataBind(); 40
} 41
catch 42
{ } 43
} 44
} 45
//绑定数据源 46
private void myDataBind() 47
{ 48
Sql s = new Sql(); 49
DataSet ds = s.getMyDataSet("select * from keyarray order by id desc"); 50
GridView1.DataSource = ds; 51
GridView1.DataBind(); 52
} 53
//添加广告关键字 54
protected void Button1_Click(object sender, EventArgs e) 55
{ 56
int result; 57
Sql s = new Sql(); 58
//添加关键字 59
result = s.ExecuteSql("insert into keyarray([name],notes) values('"+TextBox1.Text+"','"+ TextBox2.Text+"')"); 60
string msg = "alert('操作错误!')"; 61
if (result==1)//如果操作成功,提示 62
{ 63
TextBox2.Text = TextBox1.Text = ""; 64
msg = "alert('操作成功!')"; 65
myDataBind(); 66
} 67
//客户端提示 68
ClientScript.RegisterStartupScript(this.GetType(), "asdf", msg, true); 69
} 70
} 71






}