?? addsubject.aspx.cs
字號(hào):
?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.SqlClient;
public partial class AddSubject : System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
if(!Page.IsPostBack)
{ ///顯示數(shù)據(jù)
BindTopicData();
}
AddBtn.Enabled = TopicList.Items.Count > 0 ? true : false;
}
private void BindTopicData()
{ ///獲取數(shù)據(jù)
ITopic topic = new Topic();
SqlDataReader dr = topic.GetTopics();
///綁定數(shù)據(jù)
TopicList.DataSource = dr;
///設(shè)置Text屬性和Value屬性的值
TopicList.DataTextField = "Name";
TopicList.DataValueField = "TopicID";
TopicList.DataBind();
///關(guān)閉數(shù)據(jù)源
dr.Close();
}
protected void AddBtn_Click(object sender,EventArgs e)
{
try
{ ///定義對(duì)象
ISubject subject = new Subject();
///執(zhí)行數(shù)據(jù)庫(kù)操作
subject.AddSubject(Name.Text.Trim(),
Int32.Parse(ModeList.SelectedValue),
Int32.Parse(TopicList.SelectedValue));
Response.Write("<script>alert('" + "添加數(shù)據(jù)成功,請(qǐng)妥善保管好你的數(shù)據(jù)!" + "');</script>");
}
catch(Exception ex)
{ ///跳轉(zhuǎn)到異常錯(cuò)誤處理頁(yè)面
Response.Redirect("ErrorPage.aspx?ErrorMsg=" + ex.Message.Replace("<br>","").Replace("\n","")
+ "&ErrorUrl=" + Request.Url.ToString().Replace("<br>","").Replace("\n",""));
}
}
protected void ReturnBtn_Click(object sender,EventArgs e)
{ ///跳轉(zhuǎn)到管理頁(yè)面
Response.Redirect("~/SubjectManage.aspx");
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -