zoukankan      html  css  js  c++  java
  • Webform---修改人员信息

    public partial class Edit : System.Web.UI.Page
    {
        private MyDBDataContext _Context = new MyDBDataContext();
    
        //绑定民族
        private void FillNation()
        {
            List<Nation> list = _Context.Nation.ToList();
            txtNation.DataSource = list;
            txtNation.DataTextField = "Name";
            txtNation.DataValueField = "Code";
            txtNation.DataBind();
        }
    
        //在修改页面获取人员主键值加载人员信息
        private void FillLoadInfo()
        {
            string Code = Request["id"];
            var query = _Context.Info.Where(p => p.Code == Code);
            if (query.Count() > 0)
            {
                Info data = query.First();
                txtCode.Text = data.Code;
                txtName.Text = data.Name;
                txtSex.SelectedValue = data.Sex.ToString();
                txtNation.SelectedValue = data.Nation;
                txtBirthday.Text = data.Birthday.Value.ToString("yyyy年MM月dd日");
            }
        }
        //加载民族和个人信息
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FillNation();
                FillLoadInfo();
            }
        }
    
        //返回显示信息的页面
        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("修改信息.aspx");
        }
    
        //修改更新信息
        protected void btnOk_Click(object sender, EventArgs e)
        {
            //查出要修改的对象
            string code = txtCode.Text;
            var query = _Context.Info.Where(p=>p.Code == code);
    
            if (query.Count() > 0)
            {
                Info data = query.First ();
                //修改
                data.Name  = txtName.Text ;
                data.Sex = Convert.ToBoolean (txtSex.Text);
                data.Nation = txtNation.Text ;
                data.Birthday = Convert.ToDateTime (txtBirthday.Text );
    
                //提交
                _Context.SubmitChanges();
            }
        }
    }

    Repeater绑定数据:

     private MyDBDataContext _Context = new MyDBDataContext();
     
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<Info> list = _Context.Info.ToList();
                Repeater1.DataSource = list;
                Repeater1.DataBind();
            }
        }

    修改信息超链接:

    1.a标签:

    <a href="Edit.aspx?id=<%#Eval("Code") %>">修改</a>

    2.HyperLink按钮

        public string ShowHref()
        {
            return "Edit.aspx?id=" + Eval("Code");
        }
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="<%#ShowHref() %>">修改</asp:HyperLink>
                        </td>
  • 相关阅读:
    AVPlayer中的问题
    封装网络请求
    FMDB的使用方法
    设置UITextField占位符的颜色和字体
    SQL SERVER性能优化综述
    关于学习
    学习java中对《类与对象》的认知
    Felling1-java
    关于学习JAVA第二章的心得
    学习JAVA第一章的心得
  • 原文地址:https://www.cnblogs.com/qianxiaojinnian/p/4720564.html
Copyright © 2011-2022 走看看