using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Update : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if( Session["uid"]!="")
{
if( !IsPostBack)
{
InfoDataContext context = new InfoDataContext();
//给民族下拉添上数据
DropDownList1.DataSource = context.Nation;
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "Code";
DropDownList1.DataBind();
//查询数据
string code=Request["Code"].ToString();
Info data = context.Info.Where(p=>p.Code==code).First();
//传值
txtCode.Text = data.Code;
txtName.Text = data.Name;
txtBirthday.Text = data.Birthday.Value.ToString("yyyy-MM-dd");
//判断男女进行传值
if (data.Sex == true)
{
rdnan.Checked = true;
}
else
{
rdnv.Checked = true;
}
foreach(ListItem item in DropDownList1.Items)
{
if (item.Value == data.Nation)
{
item.Selected = true;
}
}
}
}
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 = context.Info.Where(p=>p.Code==code).First();
//修改数据
data.Name = name;
data.Sex = sex;
data.Nation = nation;
data.Birthday = birthday;
context.SubmitChanges();
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Main.aspx");
}
}