三层架构编辑


ClassInfo.aspx前台页面


名称:<%----%>

<%-- --%>





<%-- //MultiLine文本框,textarae--%>
内容:





ClassInfoAdd.aspx.cs后台页面

双击添加按钮进入一个button事件在时间里面写:

//获取name和content的值
var name = TextBox1.Value;
var content = TextBox2.Text;
Model.ClassInfo info = new Model.ClassInfo()
{
//给Name和Content 赋值
Name = name,
Content = content
};
if (BLL.ClassInfoBLL.Insert(info)>0)
{
Response.Write("");

修改

DAL

public static int Update(ClassInfo info)
{
var sql = "update classinfo set name=@name,content=@content where id=@id";
SqlParameter[] sqlp = new SqlParameter[]
{
new SqlParameter("@id",info.Id),
new SqlParameter("@name",info.Name),

new SqlParameter("@content",info.Content)
};

return Class1.NonQuery(sql, sqlp);
}

BLL

public static int Update(ClassInfo info)
{
return ClassInfoDAL.Update(info);
}

ClassInfoUpdate.aspx页面


<%-- //readonly只读--%>
编号:


<%-- //required必填项--%>
名称:<%----%>







<%-- //MultiLine文本框,textarae--%>
内容:



<%-- PostBackUrl="~/ClassInfo.aspx" 跳转到ClassInfo.aspx页面--%>

ClassInfo.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;

//服务器第一次加载非刷新时
if (!IsPostBack)
{
int id = Convert.ToInt32(Request.QueryString["Id"]);
var info = BLL.ClassInfoBLL.Select(id);
if (info != null)
{
Text1.Value = info.Id + "";
TextBox1.Value = info.Name;
TextBox2.Text = info.Content;
}
else
{
Response.Redirect("ClassInfo.aspx");
}
}

修改按钮双击

protected void Button1_Click(object sender, EventArgs e)
{
Model.ClassInfo info = new Model.ClassInfo()
{
Id = Convert.ToInt32(Text1.Value),
Name = TextBox1.Value,
Content = TextBox2.Text
};
if (BLL.ClassInfoBLL.Update(info)>0)
{
Response.Write("");
}
}
}
}

相关