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<Productor> 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<Brand> 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<Car> 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" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div> <asp:DropDownList ID="ddlProd" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlProd_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="ddlBrand" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlBrand_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="ddlCar" runat="server">
</asp:DropDownList> </div>
</form>
</body>
</html>

三级联动下拉HTML

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; /// <summary>
/// Info 的摘要说明
/// </summary>
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" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
.trover {
background-color:green;
}
</style>
<script language="javascript"> function doOver(tr) {
//tr.style.backgroundColor = "yellow";
tr.className = "trover";
}
function doOut(tr) {
//tr.style.backgroundColor = ""; tr.className = "";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ul id="uu"></ul>
<div> <asp:Repeater ID="Repeater1" runat="server" >
<HeaderTemplate>
<table width="100%" border="1">
</HeaderTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<ItemTemplate>
<tr onmouseover="doOver(this)" onmouseout="doOut(this)">
<td><%# Eval("Code") %></td>
<td><%# Eval("Name") %></td>
<td><%# Eval("SexName") %></td>
<td><%# Eval("NationName") %></td>
<td><%# Eval("Birthday","{0:yyyy年MM月dd日}") %></td>
<td>
<%--<a href="Edit.aspx?id=<%# Eval("Code") %>">修改</a>--%>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="#" onclick="<%# ShowClickScript() %>">修改</asp:HyperLink>
<a href="Delete.aspx?id=<%# Eval("Code") %>" onclick="return confirm('确认要删除吗?')" >删除</a>
<asp:Button ID="Button1" OnClick="Button1_Click" CommandArgument="<%# SetKey() %>" runat="server" Text="删除" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater> </div>
<asp:HyperLink ID="HyperLink2" runat="server" onclick="window.open('Add.aspx','_blank','width=300 height=300');return false;" NavigateUrl="#">添加</asp:HyperLink>
</form>
</body>
</html>
<script language="javascript">
var li = document.createElement("li");
li.innerHTML = "苹果"
document.getElementById("uu").appendChild(li); alert(
"asdfasdf"
);
document.getElementById("uu").removeChild(li);
</script>

添加修改删除 主界面

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<Info> 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() > )
{
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" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<h1>添加</h1>
<form id="form1" runat="server">
<div> 代号:<asp:TextBox ID="txtCode" runat="server" Text=""></asp:TextBox>
<br />
姓名:<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<br />
性别:<asp:RadioButtonList ID="txtSex" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem Value="True">男</asp:ListItem>
<asp:ListItem Value="False">女</asp:ListItem>
</asp:RadioButtonList>
<br />
民族:<asp:DropDownList ID="txtNation" runat="server">
</asp:DropDownList>
<br />
生日:<asp:TextBox ID="txtBirthday" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnOK" runat="server" Text="添加" OnClick="btnOK_Click" /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="返回" /> </div>
<div> <asp:Literal ID="Literal1" runat="server"></asp:Literal> </div>
</form>
</body>
</html>

添加界面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<Nation> 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 = "<script language=javascript>window.opener.location.reload();window.close();</script>";
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");
}
}

添加界面C#

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>修改</h1>
<div> 代号:<asp:Label ID="txtCode" runat="server" Text="Label"></asp:Label>
<br />
姓名:<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<br />
性别:<asp:RadioButtonList ID="txtSex" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem Value="True">男</asp:ListItem>
<asp:ListItem Value="False">女</asp:ListItem>
</asp:RadioButtonList>
<br />
民族:<asp:DropDownList ID="txtNation" runat="server">
</asp:DropDownList>
<br />
生日:<asp:TextBox ID="txtBirthday" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnOK" runat="server" Text="更新" OnClick="btnOK_Click" /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="返回" /> <asp:Literal ID="Literal1" runat="server"></asp:Literal> </div>
</div>
</form>
</body>
</html>

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() > )
{
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<Nation> 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() > )
{
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 = "<script language=javascript>window.opener.location.reload();window.close();</script>";
}
}
}

C#

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div> </div>
</form>
</body>
</html>

删除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() > )
{
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#删除

Web 1三级联动 下拉框 2添加修改删除 弹框的更多相关文章

  1. Android实现三级联动下拉框 下拉列表spinner

    Android实现(省.市.县)三级联动下拉框 下拉列表spinner 转载请注明出处: http://www.goteny.com/articles/2013/11/46.html http://w ...

  2. JS年月日三级联动下拉框日期选择代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. jquery+html三级联动下拉框

    jquery+html三级联动下拉框及详情页面加载时的select初始化问题   html写的三个下拉框,如下: <select name="ddlQYWZYJ" id=&q ...

  4. jquery+ligerform三级联动下拉框

    如下为ligerform里的三级联动下拉框: var formData=[ {display:,width:,space:,type:"select",group:"区域 ...

  5. 项目总结01:JSP mysql SpringMvc下中国省市县三级联动下拉框

    JSP mysql SpringMvc下中国省市县三级联动下拉框 关键词 JSP  mysql数据库  SpringMvc  ajax   Controller层  Service层  中国地区  省 ...

  6. 用jsp实现省市区三级联动下拉

    jsp+jquery实现省市区三级联动下拉 不少系统都需要实现省市区三级联动下拉,像人口信息管理.电子商务网站.会员管理等,都需要填写地址相关信息.而用ajax实现的无刷新省市区三级联动下拉则可以改善 ...

  7. PHP用ajia代码写三级联动下拉

    下面是我做三级联动下拉的步骤以及逻辑 第一步:先做一个省市区表格 第二步:建个PHP页面显示用我是在<body>里放<div>用来接收要显示的省市区表格信息,里面嵌入jquer ...

  8. JQ与AJAX 省市区三级联动下拉框

    用于初学者学习基本的联动下拉框,废话不多说,见代码 首先看控制器里的3个下拉框对应代码: public ActionResult GetProvinceList() { ProvinceReposit ...

  9. jquery+html三级联动下拉框及详情页面加载时的select初始化问题

    html写的三个下拉框,如下: <select name="ddlQYWZYJ" id="ddl_QYWZYJ" class="fieldsel ...

随机推荐

  1. Oracle11g R2学习系列 之一安装篇

    前言 最近想去前同事推荐的一个Oracle相关的岗位竞争一下,由于之前没有使用Oracle的相关经验,所以决定学习一下,就算最终岗位应聘不成,至少也有了一些Oracle经验了,说不定哪天就用上了.再说 ...

  2. 火狐的bug

    初次启动火狐的界面并且默认是最大化的情况下,第一个业签时会发现火狐的浏览器无法达到下边框,请看图 途中可以看到,body区域没有填充满浏览器可用区域.但是当浏览器已经启动页签,现在是第二个页签时,则不 ...

  3. android图像模糊技术

    今天我们来更深入了解一下Android开发上的模糊技术.我读过几篇有关的文章,也在StackOverFlow上看过一些相关教程的帖子,所以我想在这里总结一下学到的东西. 为什么学习这个模糊技术? 现在 ...

  4. sudo 无法解析主机的解决办法

    错误存在于更改主机名字后,解决办法如下: sudo gedit /etc/hosts找到如下行:127.0.1.1       XXX将其修改为:127.0.1.1       (你现在的主机名) 保 ...

  5. 使用Japserreport填充报表数据(3)

    E中以PDF文件的格式显示静态的中文字符串,在大多数的情况下,打印的数据来自于一些变量,在JasperReports工具中传递数据并填充到 报表只有两种方式,即使用Parameters参数和JRDat ...

  6. [linux] linux知识积累(不断更新中…)

    一.vim知识 f(find)命令也可以用于移动,fx将找到光标后第一个为x的字符,3fd将找到第三个为d的字符. D 删除当前字符至行尾.D=d$ :split或new 打开一个新窗口,光标停在顶层 ...

  7. CC2530定时器3的输入捕获中断

    CC2530定时器3的输入捕获中断 使用的是tim3的通道1的输入捕获P1_7口.//GPIO配置成复用功能,同时设置P1_7为输入.void irCaptureGpioInit(void){ P1S ...

  8. 存储过程--表变量和while简单运用

    1.sql创建表/*订单*/CREATE TABLE Orders ( PRIMARY KEY(Id), Id int, Name varchar(20))2.存储过程ProTestDT    1)创 ...

  9. C语言 中缀转后缀

    给定字符串型的算术表达式,实现中缀转后缀并运算得出结果: #ifndef STACK_H_INCLUDED #define STACK_H_INCLUDED #include <stdio.h& ...

  10. Smarty 变量使用

    Smarty的标签都是使用定界符括起来. 默认定界符是{ 和 }, 但定界符可以被改变. 比如说在本手册,我们会假定你在使用默认的定界符. 在Smarty看来,任何在定界符之外的内容,都是静态的,或者 ...