博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Web 1三级联动 下拉框 2添加修改删除 弹框
阅读量:6708 次
发布时间:2019-06-25

本文共 10739 字,大约阅读时间需要 35 分钟。

 

Web  三级联动 下拉框

 

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page{    private MyDBDataContext _Context = new MyDBDataContext();    private void FillProd()    {        List
list = _Context.Productor.ToList(); ddlProd.DataSource = list; ddlProd.DataTextField = "Prod_Name"; ddlProd.DataValueField = "Prod_Code"; ddlProd.DataBind(); } private void FillBrand() { string prodCode = ddlProd.SelectedValue; List
list = _Context.Brand.Where(p=>p.Prod_Code == prodCode).ToList(); ddlBrand.DataSource = list; ddlBrand.DataTextField = "Brand_Name"; ddlBrand.DataValueField = "Brand_Code"; ddlBrand.DataBind(); } private void FillCar() { string brandCode = ddlBrand.SelectedValue; List
list = _Context.Car.Where(p=>p.Brand == brandCode).ToList(); ddlCar.DataSource = list; ddlCar.DataTextField = "Name"; ddlCar.DataValueField = "Code"; ddlCar.DataBind(); } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { FillProd(); FillBrand(); FillCar(); } } protected void ddlProd_SelectedIndexChanged(object sender, EventArgs e) { FillBrand(); FillCar(); } protected void ddlBrand_SelectedIndexChanged(object sender, EventArgs e) { FillCar(); }}
三级联动下拉C#
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
三级联动下拉HTML

 

 

 

 

using System;using System.Collections.Generic;using System.Linq;using System.Web;/// /// Info 的摘要说明/// public partial class Info{    public string SexName    {        get        {            if (this.Sex.Value == true)                return "男";            else                return "女";        }    }    public string NationName    {        get        {            return this.Nation1 .Name;        }    }}

  

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
    <%# Eval("Code") %> <%# Eval("Name") %> <%# Eval("SexName") %> <%# Eval("NationName") %> <%# Eval("Birthday","{0:yyyy年MM月dd日}") %> <%--
    ">修改--%>
    修改
    " οnclick="return confirm('确认要删除吗?')" >删除
    添加
    添加修改删除 主界面
    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Default2 : System.Web.UI.Page{    private MyDBDataContext _Context = new MyDBDataContext();    public string SetKey()    {        return Eval("Code").ToString();    }    public string ShowClickScript()    {        string url = "Edit.aspx?id=" + Eval("Code");        string s = "window.open('"+url+"','_blank','width=300 height=300');return false;";        return s;    }    public string ShowHref()    {        return "Edit.aspx?id=" + Eval("Code");    }    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            Show();        }    }    private void Show()    {        //查数据        List
    list = _Context.Info.ToList(); //填进去 Repeater1.DataSource = list; Repeater1.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { //删除的代码。 //找到被点击的删除按钮 Button btn = (Button)sender; //找到按钮上的主键值 string code = btn.CommandArgument.ToString(); //删除 //1.找到要删除的对象 var query = _Context.Info.Where(p => p.Code == code); if (query.Count() > 0) { Info data = query.First(); //2.告诉上下文 _Context.Work.DeleteAllOnSubmit(data.Work); _Context.Family.DeleteAllOnSubmit(data.Family); _Context.Info.DeleteOnSubmit(data); //3.提交 _Context.SubmitChanges(); } Show(); }}
    添加修改删除主界面 C#

     

     

     

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Add.aspx.cs" Inherits="Add" %>

    添加

    代号:
    姓名:
    性别:
    民族:
    生日:
    添加界面html
    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Add : System.Web.UI.Page{    private MyDBDataContext _Context = new MyDBDataContext();    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            FillNation();        }    }    private void FillNation()    {        List
    list = _Context.Nation.ToList(); txtNation.DataSource = list; txtNation.DataTextField = "Name"; txtNation.DataValueField = "Code"; txtNation.DataBind(); } protected void btnOK_Click(object sender, EventArgs e) { //把界面上的值取出来 string code = txtCode.Text; string name = txtName.Text; bool sex = Convert.ToBoolean(txtSex.SelectedValue); string nation = txtNation.SelectedValue; DateTime birthday = Convert.ToDateTime(txtBirthday.Text); //送到数据库中去 //1.造个对象 Info data = new Info(); data.Code = code; data.Name = name; data.Sex = sex; data.Nation = nation; data.Birthday = birthday; //2.告诉上下文 _Context.Info.InsertOnSubmit(data); //3.提交 _Context.SubmitChanges(); //跳转 //Response.Redirect("Default2.aspx"); Literal1.Text = "
    "; } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("Default2.aspx"); }}
    添加界面C#

     

     

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Edit.aspx.cs" Inherits="Edit" %>

    修改

    代号:
    姓名:
    性别:
    民族:
    生日:
    HTML
    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Edit : System.Web.UI.Page{    private MyDBDataContext _Context = new MyDBDataContext();    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            FillNation();  //填充民族            LoadInfo(); //加载人员信息        }    }    private void LoadInfo()    {        //获取要修改的人员值        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");        }    }    private void FillNation()    {        List
    list = _Context.Nation.ToList(); txtNation.DataSource = list; txtNation.DataTextField = "Name"; txtNation.DataValueField = "Code"; txtNation.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("Default2.aspx"); } protected void btnOK_Click(object sender, EventArgs e) { //把界面上的值取出来, string code = txtCode.Text; string name = txtName.Text; bool sex = Convert.ToBoolean(txtSex.SelectedValue); string nation = txtNation.SelectedValue; DateTime birthday = Convert.ToDateTime(txtBirthday.Text); //送加数据库 //1.查询要修改的对象 var query = _Context.Info.Where(p=>p.Code == code); if (query.Count() > 0) { Info data = query.First(); //2.把值修改一下。 data.Name = name; data.Sex = sex; data.Nation = nation; data.Birthday = birthday; //3.提交送回数据 _Context.SubmitChange() _Context.SubmitChanges(); //跳转 //Response.Redirect("Default2.aspx"); Literal1.Text = "
    "; } }}
    C#

     

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Delete.aspx.cs" Inherits="Delete" %>
    删除html

     

    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Delete : System.Web.UI.Page{    private MyDBDataContext _Context = new MyDBDataContext();    protected void Page_Load(object sender, EventArgs e)    {        //找出主键值        string code = Request["id"];        //删除        //1.找到要删除的对象        var query = _Context.Info.Where(p=>p.Code == code);        if (query.Count() > 0)        {            Info data = query.First();            //2.告诉上下文            _Context.Work.DeleteAllOnSubmit(data.Work);            _Context.Family.DeleteAllOnSubmit(data.Family);            _Context.Info.DeleteOnSubmit(data);            //3.提交            _Context.SubmitChanges();        }        //跳转        Response.Redirect("Default2.aspx");    }}
    c#删除

     

    转载于:https://www.cnblogs.com/981971554nb/p/4738919.html

    你可能感兴趣的文章
    利用Nginx做负载均衡
    查看>>
    CentOS 7 本地yum源配置
    查看>>
    python 将unix文件转成dos文件
    查看>>
    ORA-01114: IO error writing block to file
    查看>>
    javascript 使用btoa和atob来进行Base64转码和解码
    查看>>
    让Windows7更安全 不得不知的帐户设置
    查看>>
    设计模式系列-享元模式
    查看>>
    电子课本的未来
    查看>>
    CactiEZ中文版10.1正式发布
    查看>>
    Linux命令之top
    查看>>
    中断和异常
    查看>>
    字符串的处理2
    查看>>
    android - 自定义(组合)控件 + 自定义控件外观
    查看>>
    关于subpartition(hash)在表空间中的分布
    查看>>
    java 对象序列化
    查看>>
    我的友情链接
    查看>>
    jplayer播放插件
    查看>>
    telnet localhost 25
    查看>>
    51次课(设置更改root密码、连接mysql、mysql常用命令)
    查看>>
    设置logcat中log颜色
    查看>>