温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:内文广告管理系统V1.1版源码
当前文件:
TextAd/admin2.aspx.cs,打开代码结构图
TextAd/admin2.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 admin2 : System.Web.UI.Page 12
{ 13
//该 源 码下载自www.51aspx.com(51aspx.c om) 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 ad where id=" + id);//删除 39
myDataBind(); 40
} 41
catch 42
{ } 43
} 44
} 45
//绑定数据源 46
private void myDataBind() 47
{ 48
Sql s = new Sql(); 49
string str = "select ad.*,keyarray.name from ad inner join keyarray on ad.keyid=keyarray.id order by ad.id desc"; 50
DataSet ds = s.getMyDataSet(str);//所有广告内容 51
GridView1.DataSource = ds; 52
GridView1.DataBind(); 53
} 54
//添加广告内容 55
protected void Button1_Click(object sender, EventArgs e) 56
{ 57
int result; 58
Sql s = new Sql(); 59
//添加广告内容 60
result =s.ExecuteSql("insert into ad(keyid,description,url) values('"+ DropDownList1.SelectedValue +"','"+ TextBox2.Text+"','"+ TextBox1.Text+"')"); 61
string msg = "alert('操作错误!')"; 62
if (result==1)//如果操作成功,提示 63
{ 64
TextBox2.Text = TextBox1.Text = ""; 65
msg = "alert('操作成功!')"; 66
myDataBind(); 67
} 68
//客户端提示 69
ClientScript.RegisterStartupScript(this.GetType(), "asdf", msg, true); 70
} 71
} 72






}