其他分享
首页 > 其他分享> > 11.18UI层调用方法及绑定数据

11.18UI层调用方法及绑定数据

作者:互联网

 

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>");
}

 

标签:info,Comment,ClassInfo,11.18,Text,绑定,UI,var,ClassInfoBLL
来源: https://www.cnblogs.com/malongfei/p/15599698.html