温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:简单多功能投票/调查系统源码
当前文件路径:Votes/TopicManage.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
using System.Data.SqlClient; 12
13
public partial class TopicManage : System.Web.UI.Page 14
{ 15
private int sid; 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
if (!Page.IsPostBack) BindTopicData(); 19
} 20
21
public void BindTopicData() 22
{ 23
ITopics topic = new Topics(); 24
SqlDataReader dr = topic.GetAllTopic(); 25
TopicView.DataSource = dr; 26
TopicView.DataBind(); 27
dr.Close(); 28
} 29
30
protected void VoteView_RowDataBound(object sender,GridViewRowEventArgs e) 31
{ 32
ImageButton imagebutton = (ImageButton)e.Row.FindControl("imagebtn"); 33
if (imagebutton != null) 34
imagebutton.Attributes.Add("onclick","return confirm('确定删除么?');"); 35
} 36
37
protected void VoteView_RowCommand(object sender,GridViewCommandEventArgs e) 38
{ 39
if(Int32.TryParse(e.CommandArgument.ToString(),out sid)==false||e.CommandName=="") 40
{ 41
Response.Write("<script>alert('没有接收到参数!');</script>"); 42
return; 43
} 44
ITopics topic = new Topics(); 45
switch (e.CommandName) 46
{ 47
case "delete": 48
topic.DeleteTopic(sid); 49
Response.Write("<script>alert('删除成功! ');</script>"); 50
BindTopicData(); 51
break; 52
53
case "update": 54
SqlDataReader dr = topic.GetTopic(sid); 55
if (dr.Read()) 56
{ 57
name.Text=dr["t_name"].ToString(); 58
content.Text=dr["t_content"].ToString(); 59
AddUpdate.Text = "修改投票主题"; 60
AddUpdatebtn.Text = "修改主题"; 61
AddUpdatebtn.CommandName = "update"; ///将CommandName、CommandArgument传给ID=AddUpdatebtn的按钮 62
AddUpdatebtn.CommandArgument = sid.ToString(); 63
} 64
dr.Close(); 65
break; 66
67
case "iscurrent": 68
topic.UpdateCurrentTopicByProc(sid); 69
Response.Write("<script>alert('更新前台主题成功! ');</script>"); 70
BindTopicData(); 71
break; 72
} 73
} 74
75
protected void AddUpdatebtn_Click(object sender, EventArgs e) 76
{ 77
if (name.Text.Trim().Length < 2 || content.Text.Trim().Length < 2) 78
{ 79
Response.Write("<script>alert('字数不够');</script>"); 80
return; 81
} 82
ITopics topic=new Topics(); 83
switch (AddUpdatebtn.CommandName) ///根据AddUpdatebtn.CommandName分为添加和更新,因为不是RowDataBound所以不能用e.CommandName 84
{ 85
case "add": 86
try 87
{ 88
topic.AddTopic(name.Text.Trim().ToString(), content.Text.Trim().ToString()); 89
Response.Write("<script>alert('新增成功! ');</script>"); 90
BindTopicData(); 91
} 92
catch (Exception ex) 93
{ 94
Response.Redirect("ErrorPage.aspx?ErrorUrl=" + Request.Url.ToString().Replace("<br>", "").Replace("\n", "") + "&ErrorMsg=" + ex.Message.Replace("<br>", "").Replace("\n", "")); 95
} 96
break; 97
98
case "update": 99
try 100
{ 101
topic.UpdateTopic(name.Text.Trim().ToString(), content.Text.Trim().ToString(), Int32.Parse(AddUpdatebtn.CommandArgument)); 102
Response.Write("<script>alert('修改主题成功!');</script>"); 103
BindTopicData(); 104
} 105
catch (Exception ex) 106
{ 107
Response.Redirect("ErrorPage.aspx?ErrorUrl=" + Request.Url.ToString().Replace("<br>", "").Replace("\n", "") + "&ErrorMsg=" + ex.Message.Replace("<br>", "").Replace("\n", "")); 108
} 109
break; 110
} 111
112
} 113
114
protected void VoteView_RowDeleting(object sender, GridViewDeleteEventArgs e) 115
{ 116
/// 117
} 118
protected void VoteView_RowUpdating(object sender, GridViewUpdateEventArgs e) 119
{ 120
/// 121
} 122
} 123





}
}