我要写个 4个 DropDownList 连动实现 省份-城市-区县-街道,我把这个做成用户控件,并为用户控件设置4个属性以在调用页中取得省份-城市-区县-街道的值,还想在用户控件里用AjaxPanel来实现局部刷新,但是调用时 IE 状态栏有提示 脚本错误。而且无法在调用页上取得 用户控件 的4个属性。请问改怎么解决?
----------------------- ascx 代码-----------------------------
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CityList.ascx.cs" Inherits="CityList" %>
<ajax:AjaxPanel ID="AjaxPanelCityList" runat="server">
<table border="0" cellpadding="1" cellspacing="1">
<tr>
<td style="width: 95px;">
<asp:DropDownList ID="DDLProvinces" runat="server" OnSelectedIndexChanged="DDLProvinces_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList></td>
<td style="width: 95px;">
<asp:DropDownList ID="DDLCities" runat="server" Visible="False" OnSelectedIndexChanged="DDLCities_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList></td>
<td style="width: 95px;">
<asp:DropDownList ID="DDLCounties" runat="server" Visible="False" OnSelectedIndexChanged="DDLCounties_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList></td>
<td style="width: 95px;">
<asp:DropDownList ID="DDLStreets" runat="server" Visible="False" OnSelectedIndexChanged="DDLStreets_SelectedIndexChanged">
</asp:DropDownList></td>
</tr>
</table>
</ajax:AjaxPanel>------------------------ ascx.cs 代码 --------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using UNGou.BLL;public partial class CityList : System.Web.UI.UserControl
{
private int _Province;
/// <summary>
/// 省份
/// </summary>
public int Province
{
get { return _Province; }
set { _Province = value; }
} private int _City;
/// <summary>
/// 城市
/// </summary>
public int City
{
get { return _City; }
set { _City = value; }
} private int _County;
/// <summary>
///
/// </summary>
public int County
{
get { return _County; }
set { _County = value; }
} private int _Street;
/// <summary>
/// 镇/街道
/// </summary>
public int Street
{
get { return _Street; }
set { _Street = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
this.ProvincesBind();
} //绑定省份
void ProvincesBind()
{
DDLProvinces.DataSource = CityInfoBLL.GetALLSF().Tables["Temp"];
DDLProvinces.DataTextField = "CityName";
DDLProvinces.DataValueField = "PKID";
DDLProvinces.DataBind();
DDLProvinces.Items.Insert(0, new ListItem("请选择省份", "0"));
} //绑定城市
void CitiesBind(int oneId)
{
DDLCities.DataSource = CityInfoBLL.GetChenShi(oneId);
DDLCities.DataTextField = "CityName";
DDLCities.DataValueField = "PKID";
DDLCities.DataBind();
DDLCities.Items.Insert(0, new ListItem("请选择城市", "0"));
} //绑定县/区
void CountiesBind(int twoId)
{
DDLCounties.DataSource = CityInfoBLL.GetXian(twoId);
DDLCounties.DataTextField = "CityName";
DDLCounties.DataValueField = "PKID";
DDLCounties.DataBind();
DDLCounties.Items.Insert(0, new ListItem("请选择县/区", "0"));
} //绑定镇/街道
void StreetBind(int threeId)
{
DDLStreets.DataSource = CityInfoBLL.GetZhen(threeId);
DDLStreets.DataTextField = "CityName";
DDLStreets.DataValueField = "PKID";
DDLStreets.DataBind();
DDLStreets.Items.Insert(0, new ListItem("请选择镇/街道", "0"));
} //选择省份后触发
protected void DDLProvinces_SelectedIndexChanged(object sender, EventArgs e)
{
this.Province = Int32.Parse(DDLProvinces.SelectedValue);
this.DDLCities.Visible = true;
this.DDLCounties.Visible = false;
this.DDLStreets.Visible = false;
this.CitiesBind(Int32.Parse(DDLProvinces.SelectedValue));
this.DDLCities.Focus();
} //选择城市后触发
protected void DDLCities_SelectedIndexChanged(object sender, EventArgs e)
{
this.City = Int32.Parse(DDLCities.SelectedValue);
MagicAjax.AjaxCallHelper.WriteAlert(DDLCities.SelectedItem.Text+this.City.ToString());
this.DDLCounties.Visible = true;
this.DDLStreets.Visible = false;
this.CountiesBind(Int32.Parse(DDLCities.SelectedValue));
this.DDLCounties.Focus();
} //选择区县后触发
protected void DDLCounties_SelectedIndexChanged(object sender, EventArgs e)
{
this.County = Int32.Parse(DDLCounties.SelectedValue);
this.DDLStreets.Visible = true;
this.StreetBind(Int32.Parse(DDLCounties.SelectedValue));
this.DDLStreets.Focus();
}
protected void DDLStreets_SelectedIndexChanged(object sender, EventArgs e)
{
this.Street = Int32.Parse(DDLStreets.SelectedValue);
}
}-----------------------------------
----------------------- ascx 代码-----------------------------
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CityList.ascx.cs" Inherits="CityList" %>
<ajax:AjaxPanel ID="AjaxPanelCityList" runat="server">
<table border="0" cellpadding="1" cellspacing="1">
<tr>
<td style="width: 95px;">
<asp:DropDownList ID="DDLProvinces" runat="server" OnSelectedIndexChanged="DDLProvinces_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList></td>
<td style="width: 95px;">
<asp:DropDownList ID="DDLCities" runat="server" Visible="False" OnSelectedIndexChanged="DDLCities_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList></td>
<td style="width: 95px;">
<asp:DropDownList ID="DDLCounties" runat="server" Visible="False" OnSelectedIndexChanged="DDLCounties_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList></td>
<td style="width: 95px;">
<asp:DropDownList ID="DDLStreets" runat="server" Visible="False" OnSelectedIndexChanged="DDLStreets_SelectedIndexChanged">
</asp:DropDownList></td>
</tr>
</table>
</ajax:AjaxPanel>------------------------ ascx.cs 代码 --------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using UNGou.BLL;public partial class CityList : System.Web.UI.UserControl
{
private int _Province;
/// <summary>
/// 省份
/// </summary>
public int Province
{
get { return _Province; }
set { _Province = value; }
} private int _City;
/// <summary>
/// 城市
/// </summary>
public int City
{
get { return _City; }
set { _City = value; }
} private int _County;
/// <summary>
///
/// </summary>
public int County
{
get { return _County; }
set { _County = value; }
} private int _Street;
/// <summary>
/// 镇/街道
/// </summary>
public int Street
{
get { return _Street; }
set { _Street = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
this.ProvincesBind();
} //绑定省份
void ProvincesBind()
{
DDLProvinces.DataSource = CityInfoBLL.GetALLSF().Tables["Temp"];
DDLProvinces.DataTextField = "CityName";
DDLProvinces.DataValueField = "PKID";
DDLProvinces.DataBind();
DDLProvinces.Items.Insert(0, new ListItem("请选择省份", "0"));
} //绑定城市
void CitiesBind(int oneId)
{
DDLCities.DataSource = CityInfoBLL.GetChenShi(oneId);
DDLCities.DataTextField = "CityName";
DDLCities.DataValueField = "PKID";
DDLCities.DataBind();
DDLCities.Items.Insert(0, new ListItem("请选择城市", "0"));
} //绑定县/区
void CountiesBind(int twoId)
{
DDLCounties.DataSource = CityInfoBLL.GetXian(twoId);
DDLCounties.DataTextField = "CityName";
DDLCounties.DataValueField = "PKID";
DDLCounties.DataBind();
DDLCounties.Items.Insert(0, new ListItem("请选择县/区", "0"));
} //绑定镇/街道
void StreetBind(int threeId)
{
DDLStreets.DataSource = CityInfoBLL.GetZhen(threeId);
DDLStreets.DataTextField = "CityName";
DDLStreets.DataValueField = "PKID";
DDLStreets.DataBind();
DDLStreets.Items.Insert(0, new ListItem("请选择镇/街道", "0"));
} //选择省份后触发
protected void DDLProvinces_SelectedIndexChanged(object sender, EventArgs e)
{
this.Province = Int32.Parse(DDLProvinces.SelectedValue);
this.DDLCities.Visible = true;
this.DDLCounties.Visible = false;
this.DDLStreets.Visible = false;
this.CitiesBind(Int32.Parse(DDLProvinces.SelectedValue));
this.DDLCities.Focus();
} //选择城市后触发
protected void DDLCities_SelectedIndexChanged(object sender, EventArgs e)
{
this.City = Int32.Parse(DDLCities.SelectedValue);
MagicAjax.AjaxCallHelper.WriteAlert(DDLCities.SelectedItem.Text+this.City.ToString());
this.DDLCounties.Visible = true;
this.DDLStreets.Visible = false;
this.CountiesBind(Int32.Parse(DDLCities.SelectedValue));
this.DDLCounties.Focus();
} //选择区县后触发
protected void DDLCounties_SelectedIndexChanged(object sender, EventArgs e)
{
this.County = Int32.Parse(DDLCounties.SelectedValue);
this.DDLStreets.Visible = true;
this.StreetBind(Int32.Parse(DDLCounties.SelectedValue));
this.DDLStreets.Focus();
}
protected void DDLStreets_SelectedIndexChanged(object sender, EventArgs e)
{
this.Street = Int32.Parse(DDLStreets.SelectedValue);
}
}-----------------------------------
解决方案 »
- 大家在使用数据访问层时,使用sqlHelper,企业库,NHibernate,还是什么,你们使用那个多点,大项目又用那个
- 能否写一个类似MVC的OnActionExecuting的方法,可以在每个方法开始和结束的时候调用
- 使用IList泛型作为GridView数据源分页效率解决方法?
- 参数为何取不到?
- 清空Page上的Textbox
- JSP能解决的问题,我们.NET能做到吗?我们做.NET的宁愿被人看不起吗?
- 如何控制dropdownlist下拉显示的数量?
- 帮我看看怎么写这个程序
- 用VB语言来连接ACCess数据库,明明我已经声名了变量,为什么还会报错?
- .net的网站被攻击了,请高手帮忙看看怎么处理
- 将文件下载到客户端,然后打开,用什么方法?另一个问题,如何下载时只有提示框只有“保存”“取消”不要“打开”
- 这个CS如何编译
现在就是不知道为什么选择第一个下拉框后 IE显示脚本错误,错误在 行:390413 这可怎么找