infoset.aspx

前台:

<%@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="修改";
}
}
}
}

你可能感兴趣的:(.net,添加,修改,infoset.aspx)