zoukankan      html  css  js  c++  java
  • 12.22 repeater 修改

    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");
    }
    }

  • 相关阅读:
    项目
    Cache Code
    是什么限制了我们面向对象
    程序设计语言本质
    不要迷失在技术的海洋中
    程序是给自己看的还是给别人看的
    程序员的春天
    新手如何学习一门新的语言
    无废话C#设计模式之二十:Mediator
    (原创)代码分析-DataGrid实现增删(带提示)改和分页
  • 原文地址:https://www.cnblogs.com/cf924823/p/5065740.html
Copyright © 2011-2022 走看看