省市区下拉框三级联动

protected void Page_Load(object sender, EventArgs e) //加载
{
if (!IsPostBack)
{
FileSheng();
FileShi();
FileQu();
}
}

public void FileSheng() //省
{
DropSheng.DataSource=_context.ChinaStates.Where(p => p.ParentAreaCode == "0001");
DropSheng.DataTextField = "AreaName";
DropSheng.DataValueField = "AreaCode";

DropSheng.DataBind();
}

public void FileShi() //市
{
string sheng = DropSheng.SelectedValue.ToString();
DropShi.DataSource = _context.ChinaStates.Where(p => p.ParentAreaCode == sheng);
DropShi.DataTextField = "AreaName";
DropShi.DataValueField = "AreaCode";

DropShi.DataBind();
}

public void FileQu() //区
{
string shi = DropShi.SelectedValue.ToString();
DropQu.DataSource = _context.ChinaStates.Where(p => p.ParentAreaCode == shi);
DropQu.DataTextField = "AreaName";
DropQu.DataValueField = "AreaCode";

DropQu.DataBind();
}


AutoPostBack=True; //属性修改
protected void DropSheng_SelectedIndexChanged(object sender, EventArgs e)
{
FileShi();
}

AutoPostBack=True; //属性修改
protected void DropShi_SelectedIndexChanged(object sender, EventArgs e)
{
FileQu();
}

posted @ 2015-12-21 22:32  最讨厌起名字什么的了  阅读(232)  评论(0编辑  收藏  举报