using System;
using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Insert : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e) { if (Session["uid"] != null) { if (!IsPostBack) {InfoDataContext context = new InfoDataContext();
DropDownList1.DataSource = context.Nation;
DropDownList1.DataTextField = "Name"; DropDownList1.DataValueField = "Code";DropDownList1.DataBind();
}
}
else { Response.Redirect("denglu.aspx");}
}
protected void Button1_Click(object sender, EventArgs e) { InfoDataContext context = new InfoDataContext(); string code = txtCode.Text; string name = txtName.Text; bool sex = rdnan.Checked; string nation = DropDownList1.SelectedValue; DateTime birthday = Convert.ToDateTime(txtBirthday.Text); //造对象 Info data = new Info(); data.Code = code; data.Name = name; data.Sex = sex; data.Nation = nation; data.Birthday = birthday;
//提交数据改动
context.Info.InsertOnSubmit(data);context.SubmitChanges();
//清空数据
Clear(); }public void Clear()
{txtCode.Text = "";
txtName.Text = ""; txtBirthday.Text = ""; DropDownList1.SelectedIndex = 0; } protected void Button2_Click(object sender, EventArgs e) { Response.Redirect("Main.aspx"); }}