前台:
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="infoset.aspx.cs"Inherits="WebApplication2.infoset"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<div>姓名:<asp:TextBoxrunat="server"ID="txt_uname"></asp:TextBox></div>
<div>学号:<asp:TextBoxrunat="server"ID="txt_code"></asp:TextBox></div>
<div>学校:<asp:TextBoxrunat="server"ID="txt_school"></asp:TextBox></div>
<div><asp:Buttonrunat="server"ID="btn_save"Text="添加"/></div>
</div>
</form>
</body>
</html>
后台:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
usingSystem.Data.SqlClient;
namespaceWebApplication2
{
publicpartialclassinfoset:System.Web.UI.Page
{
protectedoverridevoidOnInit(EventArgse)
{
btn_save.Click+=btn_save_Click;
base.OnInit(e);
}
voidbtn_save_Click(objectsender,EventArgse)
{
if(Request.QueryString["id"]!=null)
{
blltest.bllStudent.edit(int.Parse(Request.QueryString["id"]),txt_uname.Text,txt_code.Text,txt_school.Text);
form1.Controls.Add(newLiteralControl("<script>alert('修改成功');location.href='GridView.aspx';</script>"));
}
else
{
blltest.bllStudent.Add(txt_uname.Text,txt_code.Text,txt_school.Text);
form1.Controls.Add(newLiteralControl("<script>alert('添加成功');location.href='GridView.aspx';</script>"));
}
}
protectedvoidPage_Load(objectsender,EventArgse)
{
if(Request.QueryString["id"]!=null)
{
DataTabledt=blltest.bllStudent.ReadData(int.Parse(Request.QueryString["id"]));
DataRowdr=dt.Rows[0];
txt_code.Text=dr["code"].ToString();
txt_school.Text=dr["school"].ToString();
txt_uname.Text=dr["uname"].ToString();
btn_save.Text="修改";
}
}
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。