11.18UI层调用方法及绑定数据(11.18 UI layer calling method and binding data)

1.绑定方法

GridView1.DataSource = ClassInfoBLL.Select(); GridView1.DataBind();

DataSource 用来绑定BLL层调用的方法;DataBind();用来将数据绑定到前台页面;

//DatakeyNames不是随便写的,数据源中要有这一列 //keys是获取一个字段名称/值,values是获取值。

//2.删除按钮事件 var id=Convert.ToInt32(e.Keys[“Id”]); if (ClassInfoBLL.delete(id)>0) { //解决跳转丢失参数问题,path路径,Query参数 var url = Request.Url.PathAndQuery; Response.Redirect(url); }

3.添加事件

定义两个变量接受两个框输入的值

var name = TextBox1.Value; var Comment = TextBox2.Text;

调用Model

TestModel.ClassInfo info = new TestModel.ClassInfo() { Name = name, Comment = Comment };

判断是否大于0 if (BLL.ClassInfoBLL.insert(info)>0) { Response.Write(“<script>alert(‘添加成功’);location=’ClassInfo.aspx'</script>”); }

在页面显示修改数据

if (!IsPostBack) { int id = Convert.ToInt32(Request.QueryString[“Id”]); var info= BLL.ClassInfoBLL.Select(id); if (info != null) { Text1.Value = info.Id + “”; TextBox1.Text = info.Name; TextBox2.Text = info.Comment; }else { Response.Redirect(“~/ClassInfo.aspx”); } }

修改

TestModel.ClassInfo info = new TestModel.ClassInfo() { Id = Convert.ToInt32(Text1.Value), Name = TextBox1.Text, Comment = TextBox2.Text }; if (BLL.ClassInfoBLL.Update(info)>0) { Response.Write(“<script>alert(‘修改成功’);location=’ClassInfo.aspx'</script>”); }

————————

1. Binding method

GridView1.DataSource = ClassInfoBLL.Select(); GridView1.DataBind();

Datasource is used to bind the method called by Bll layer; DataBind(); Used to bind data to the foreground page;

//Datakeynames is not written casually. There should be this column in the data source / / keys is to get a field name / value, and values is to get a value.

//2.删除按钮事件 var id=Convert.ToInt32(e.Keys[“Id”]); if (ClassInfoBLL.delete(id)>0) { //解决跳转丢失参数问题,path路径,Query参数 var url = Request.Url.PathAndQuery; Response.Redirect(url); }

3. Add event

Define two variables to accept the values entered in two boxes

var name = TextBox1.Value; var Comment = TextBox2.Text;

Call model

TestModel.ClassInfo info = new TestModel.ClassInfo() { Name = name, Comment = Comment };

判断是否大于0 if (BLL.ClassInfoBLL.insert(info)>0) { Response.Write(“<script>alert(‘添加成功’);location=’ClassInfo.aspx'</script>”); }

Display modified data on the page

if (!IsPostBack) { int id = Convert.ToInt32(Request.QueryString[“Id”]); var info= BLL.ClassInfoBLL.Select(id); if (info != null) { Text1.Value = info.Id + “”; TextBox1.Text = info.Name; TextBox2.Text = info.Comment; }else { Response.Redirect(“~/ClassInfo.aspx”); } }

modify

TestModel.ClassInfo info = new TestModel.ClassInfo() { Id = Convert.ToInt32(Text1.Value), Name = TextBox1.Text, Comment = TextBox2.Text }; if (BLL.ClassInfoBLL.Update(info)>0) { Response.Write(“<script>alert(‘修改成功’);location=’ClassInfo.aspx'</script>”); }