省市县三级联动(webFrom...DropdownList)
2024-08-26 18:50:11
编辑页面
<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>
<asp:DropDownList ID="DropDownList1" runat="server" Width="100px" AutoPostBack="True" Height="50px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" style="margin-bottom: 0px" >
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" Width="100px" AutoPostBack="True" Height="50px" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server" Width="100px" AutoPostBack="True" Height="50px">
</asp:DropDownList>
</form>
</body>
</html>
编辑cs
public partial class Test2 : System.Web.UI.Page
{
public DataClassesDataContext context; protected void Page_Load(object sender, EventArgs e)
{
context = new DataClassesDataContext();
if(!IsPostBack)
{
databind("");
datashibind("");
dataxianbind("");
} }
private void databind(string parentareacode)
{ var querydata = from q in context.ChinaStates
where q.ParentAreaCode == parentareacode
select q;
DropDownList1.DataSource = querydata;//指定数据源 //DropDownList1.Items.Insert(0,new ListItem("请选择单位")); DropDownList1.DataTextField = "AreaName";//界面上显示的是地名
DropDownList1.DataValueField = "AreaCode";//存的是地区编号 DropDownList1.DataBind(); }
private void datashibind(string parentareacode)
{
var querydata = from q in context.ChinaStates
where q.ParentAreaCode ==parentareacode
select q;
DropDownList2.DataSource = querydata; DropDownList2.DataTextField = "AreaName";//界面上显示的是地名
DropDownList2.DataValueField = "AreaCode";//存的是地区编号
DropDownList2.DataBind(); }
private void dataxianbind(string parentareacode)
{ var querydata = context.ChinaStates.Where(r=>r.ParentAreaCode==parentareacode);
DropDownList3.DataSource = querydata;
DropDownList3.DataTextField = "AreaName";//界面上显示的是地名
DropDownList3.DataValueField = "AreaCode";//存的是地区编号
DropDownList3.DataBind(); }
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string code = DropDownList1.SelectedValue.ToString();
datashibind(code);
if (DropDownList2.Items.Count > )
{
string s = DropDownList2.SelectedItem.Value.ToString();
dataxianbind(s);
}
else
{
DropDownList3.Items.Clear();
} }
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
string code = DropDownList2.SelectedValue.ToString();
dataxianbind(code); }
}
最新文章
- mono for android Json 上传文件
- javascript 减少回流
- Windows7系统下JAVA运行环境下载、安装和设置(第二次更新:2012年03月14日)
- POJ 2299 逆序对
- 一、XML语法
- ios NSMethodSignature and NSInvocation 消息转发
- Python下划线的使用 _ __ __obj__
- html base2
- Linux中“is not in the sudoers file”解决方法
- Oracle创建视图view权限不足问题剖析
- Django rest framework源码分析(3)----节流
- python正则表达式--编译正则表达式re.compile
- position三种属性的区别
- 剑指offer用位运算实现两个数相加,及python相关的位操作
- 解决使用Mybatis 传入多参数使用map封装遇到的 “坑”问题
- Ubuntu18---安装Redis和简单使用Redis
- C.【转】C语言字符串与数字相互转换
- Promise,async/await解决回调地狱
- Orchard模块开发全接触4:深度改造前台
- [QT][SQLITE]学习记录一 querry 查询
热门文章
- WPF ListBox
- sysbench 安装遇到的问题
- [经验交流] Active-Active 方式设置 kubernetes master 多节点高可用
- Android生命周期
- 扫描二维码自动识别手机系统(Android/IOS)
- ubuntu 安装redis两种方式 教程
- (document).height()与$(window).height()
- CRM Setstate plugin
- yum提示This system is not registered with RHN.RHN support will be disabled.
- SQL Server 2014 SP2发布下载:数十项更新修复