コード例 #1
0
        //更新编辑数据
        protected void Button1_Click(object sender, EventArgs e)
        {
            Student s       = new Student();
            string  strName = this.txtName.Text.Trim();
            string  strAge  = this.txtAge.Text.Trim();

            s.StuId = Convert.ToInt32(ViewState["ID"]);
            if (String.IsNullOrEmpty(txtName.Text) || String.IsNullOrEmpty(txtAge.Text))
            {
                Context.Response.Write("不能保存空数据,请填好值后再更新~");
                return;
            }
            else
            {
                s.StuName = txtName.Text;
                s.StuAge  = int.Parse(txtAge.Text);
                RepStuBLL bll = new RepStuBLL();
                if (bll.UpdateStu(s))
                {
                    Response.Redirect("Main.aspx");
                }
                else
                {
                    Response.Write("更新失败!");
                }
            }
        }
コード例 #2
0
 //Repeater控件中的服务器端回发事件
 protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "delete")
     {
         int id = Convert.ToInt32(e.CommandArgument);
         //调用业务逻辑层执行删除语句
         RepStuBLL bll = new RepStuBLL();
         if (bll.DeleteById(id))
         {
             Response.Redirect("Main.aspx");
         }
         else
         {
             Response.Write("删除失败!");
         }
     }
 }
コード例 #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //首先判断是否是首次加载 如果是 则根据分页加载数据
     if (!IsPostBack)
     {
         int            pageIndex = String.IsNullOrEmpty(Request.QueryString["pageIndex"]) ? 1 : int.Parse(Request.QueryString["pageIndex"]);
         int            pageSize = String.IsNullOrEmpty(Request.QueryString["pageSize"]) ? 4 : int.Parse(Request.QueryString["pageSize"]);
         int            pageCount, recordCount;
         RepStuBLL      bll  = new RepStuBLL();
         List <Student> list = bll.SelectByPage(pageIndex, pageSize, out pageCount, out recordCount);
         Repeater1.DataSource = list;
         Repeater1.DataBind();
         //利用PageHelper实现分页
         string pageStr = PagerHelper.strPage(recordCount, pageSize, pageCount, pageIndex, "Main.aspx?pageSize=4&pageIndex=");
         Literal1.Text = pageStr;
     }
 }
コード例 #4
0
        //增加一个学生
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Student s = new Student();

            s.StuName = this.TextBox1.Text;
            s.StuAge  = int.Parse(this.TextBox2.Text);
            RepStuBLL bll = new RepStuBLL();
            bool      b   = bll.AddStu(s);

            if (b)
            {
                Response.Redirect("Main.aspx");
            }
            else
            {
                Response.Write("添加失败!");
            }
        }
コード例 #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //页面加载时 将数据显示到页面上
     if (!IsPostBack)
     {
         if (!String.IsNullOrEmpty(Request.QueryString["id"]))
         {
             int       id  = int.Parse(Request.QueryString["id"]);
             RepStuBLL bll = new RepStuBLL();
             Student   s   = bll.SelectStu(id);
             this.txtName.Text = s.StuName;
             this.txtAge.Text  = s.StuAge.ToString();
             ViewState["ID"]   = s.StuId;
         }
         else
         {
             Response.Write("该数据不存在");
         }
     }
 }