这个省市县的 联动,我想用updatepanel来实现局部刷新,怎么做啊?
这三个要拖三个 updatepanel控件吗?
我拖了一个出现这个错误
ID 为“UpdatePanel1”的控件需要页面上有 ScriptManager。ScriptManager 必须在任何需要它的控件之前出现。
我就加了, <tr class="b">
<td class="style1" align="center">请选择省份</td>
<td class="style2">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlprovince" runat="server"
onselectedindexchanged="ddlprovince_SelectedIndexChanged"
Width="185px" AutoPostBack="True">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr class="b" id="city" runat="server">
<td align="center" class="style1">请选择市</td>
<td class="style2">
<asp:DropDownList ID="ddlcity" runat="server" Width="185px" AutoPostBack="True"
onselectedindexchanged="ddlcity_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr class="b" id="country" runat="server">
<td class="style1" align="center">请选择县</td>
<td class="style2">
<asp:DropDownList ID="ddlcountry" runat="server" Width="185px" AutoPostBack="True"
onselectedindexchanged="ddlcountry_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
但是选择省,显示都没刷新啊。
解决方案 »
- asp.net xml
- vs2005中报表如何做
- sqldatasource控件给存储过程传参问题
- 含webbrowser的winform control嵌入webform的问题,求有经验的达人提示一下~
- 请教asp.net+access的系统!access可读取不可写入的问题!
- 一个关于IIS和ASP的问题
- 在.aspx.cs文件中定义了一个变量,想显示在.aspx文件中,结果不行,怎么办才行?
- 关于GridView在编辑模式下获取控件的问题?
- 看我这条语句response.write("<script>open('page1.aspx?v_id=****','',400,300)</script>") 带***的地方我想用一服务器端变量代替,能
- 急!升级MySQL后遇到的问题
- HTTP post请求问题
- javascript调用COM组件中带ref参数的方法
你的市县等并没有放在updatepanel里面,当然没反应
<td class="style1" align="center">请选择省份</td>
<td class="style2">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlprovince" runat="server"
onselectedindexchanged="ddlprovince_SelectedIndexChanged"
Width="185px" AutoPostBack="True">
</asp:DropDownList>
</ContentTemplate>
</td>
</tr>
<tr class="b" id="city" runat="server">
<td align="center" class="style1">请选择市</td>
<td class="style2">
<asp:DropDownList ID="ddlcity" runat="server" Width="185px" AutoPostBack="True"
onselectedindexchanged="ddlcity_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr class="b" id="country" runat="server">
<td class="style1" align="center">请选择县</td>
<td class="style2">
<asp:DropDownList ID="ddlcountry" runat="server" Width="185px" AutoPostBack="True"
onselectedindexchanged="ddlcountry_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
</asp:UpdatePanel>
</asp:ScriptManager>
这个控件要怎么办呢?
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:updatepanel... >
<...省>
<...市>
...
</asp:updatepannel>
<body>
</asp:ScriptManager> 这个还是原样
<td class="style1" align="center">请选择省份</td>
<td class="style2">
<asp:DropDownList ID="ddlprovince" runat="server"
onselectedindexchanged="ddlprovince_SelectedIndexChanged"
Width="185px" AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
<tr class="b" id="city" runat="server">
<td align="center" class="style1">请选择市</td>
<td class="style2">
<asp:DropDownList ID="ddlcity" runat="server" Width="185px" AutoPostBack="True"
onselectedindexchanged="ddlcity_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr class="b" id="country" runat="server">
<td class="style1" align="center">请选择县</td>
<td class="style2">
<asp:DropDownList ID="ddlcountry" runat="server" Width="185px" AutoPostBack="True"
onselectedindexchanged="ddlcountry_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlprovince" runat="server"
onselectedindexchanged="ddlprovince_SelectedIndexChanged"
Width="185px" AutoPostBack="True">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
不必放在updatepanel里面 你要实现局部刷新的代码必须放在UpdatePanel里面
<table>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:updatepanel...>
省:<asp:drodownlist..../>
市:<asp:drodownlist..../>
县:<asp:drodownlist..../>
</asp:updatepanel>
</td>
</tr>
</table>
<form>
<updatemanage>
</updatemanage><updatepanal>
这里面就放你不刷新的数据就可以了
</updatepanal></form>
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table>
<tr class="b">
<td class="style1" align="center">
请选择省份
</td>
<td class="style2">
<asp:DropDownList ID="ddlprovince " runat="server" OnSelectedIndexChanged="ddlprovince_SelectedIndexChanged"
Width="185px" AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
<tr class="b" id="city" runat="server">
<td align="center" class="style1">
请选择市
</td>
<td class="style2">
<asp:DropDownList ID="ddlcity " runat="server" Width="185px" AutoPostBack="True"
OnSelectedIndexChanged="ddlcity_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr class="b" id="country" runat="server">
<td class="style1" align="center">
请选择县
</td>
<td class="style2">
<asp:DropDownList ID="ddlcountry" runat="server" Width="185px" AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
楼主,这样写就可以了。
<asp:ScriptManager ID="ScriptManager2" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<table>
<tr class="b">
<td class="style1" align="center">
请选择省份
</td>
<td class="style2">
<asp:DropDownList ID="ddlprovince " runat="server" OnSelectedIndexChanged="ddlprovince_SelectedIndexChanged"
Width="185px" AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
<tr class="b" id="city" runat="server">
<td align="center" class="style1">
请选择市
</td>
<td class="style2">
<asp:DropDownList ID="ddlcity " runat="server" Width="185px" AutoPostBack="True"
OnSelectedIndexChanged="ddlcity_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr class="b" id="country" runat="server">
<td class="style1" align="center">
请选择县
</td>
<td class="style2">
<asp:DropDownList ID="ddlcountry" runat="server" Width="185px" AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
应该没有问题了。
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true" EnableScriptLocalization="true">
</asp:ScriptManager>
放到最前面去,Form的后面
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table>
<tr class="b">
<td class="style1" align="center">请选择省份</td>
<td class="style2"> <asp:DropDownList ID="ddlprovince" runat="server"
onselectedindexchanged="ddlprovince_SelectedIndexChanged"
Width="185px" AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
<tr class="b" id="city" runat="server">
<td align="center" class="style1">请选择市</td>
<td class="style2">
<asp:DropDownList ID="ddlcity" runat="server" Width="185px" AutoPostBack="True"
onselectedindexchanged="ddlcity_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr class="b" id="country" runat="server">
<td class="style1" align="center">请选择县</td>
<td class="style2">
<asp:DropDownList ID="ddlcountry" runat="server" Width="185px" AutoPostBack="True"
onselectedindexchanged="ddlcountry_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr> </table>
</ContentTemplate>
</asp:UpdatePanel>
</form>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DDL_PRO" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDL_PRO_SelectedIndexChanged"
Width="150px">
</asp:DropDownList>
<asp:DropDownList ID="DDL_City" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDL_City_SelectedIndexChanged"
Width="150px">
</asp:DropDownList>
<asp:DropDownList ID="DDL_Dis" runat="server" Width="150px">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
public void bind()
{
DBClass db = new DBClass();
//---------------------------------绑定省到DDL_PRO
DataTable dt1 = db.GetRecords("select * from S_Province");
this.DDL_PRO.DataSource = dt1;
this.DDL_PRO.DataTextField = "ProvinceNAME";
this.DDL_PRO.DataValueField = "ProvinceID";
this.DDL_PRO.DataBind();
//---------------------------------绑定市到DDL_City
DataTable dt2 = db.GetRecords("select * from S_city where ProvinceID=" + DDL_PRO.SelectedValue);
this.DDL_City.DataSource = dt2;
this.DDL_City.DataTextField = "CityName";
this.DDL_City.DataValueField = "CityID";
this.DDL_City.DataBind();
//---------------------------------绑定县到DDL_Dis
DataTable dt3 = db.GetRecords("select * from S_District where CityID=" + DDL_City.SelectedValue);
if (dt3.Rows.Count == 0)
{
DDL_Dis.Visible = false;
}
else
{
DDL_Dis.Visible = true;
this.DDL_Dis.DataSource = dt3;
this.DDL_Dis.DataTextField = "DistrictName";
this.DDL_Dis.DataValueField = "DistrictID";
this.DDL_Dis.DataBind();
}
if (DDL_PRO.SelectedItem.Text == DDL_City.SelectedItem.Text)
{
DDL_City.Visible = false;
}
else
{
DDL_City.Visible = true;
}
} protected void DDL_PRO_SelectedIndexChanged(object sender, EventArgs e)
{
DBClass db = new DBClass();
DataTable dt2 = db.GetRecords("select * from S_city where ProvinceID=" + DDL_PRO.SelectedValue);
this.DDL_City.DataSource = dt2;
this.DDL_City.DataTextField = "CityName";
this.DDL_City.DataValueField = "CityID";
this.DDL_City.DataBind(); DataTable dt3 = db.GetRecords("select * from S_District where CityID=" + DDL_City.SelectedValue);
if (dt3.Rows.Count == 0)
{
DDL_Dis.Visible = false;
}
else
{
DDL_Dis.Visible = true;
this.DDL_Dis.DataSource = dt3;
this.DDL_Dis.DataTextField = "DistrictName";
this.DDL_Dis.DataValueField = "DistrictID";
this.DDL_Dis.DataBind();
}
if (DDL_PRO.SelectedItem.Text == DDL_City.SelectedItem.Text)
{
DDL_City.Visible = false;
}
else
{
DDL_City.Visible = true;
}
}
protected void DDL_City_SelectedIndexChanged(object sender, EventArgs e)
{
DBClass db = new DBClass();
DataTable dt3 = db.GetRecords("select * from S_District where CityID=" + DDL_City.SelectedValue);
if (dt3.Rows.Count == 0)
{
DDL_Dis.Visible = false;
}
else
{
DDL_Dis.Visible = true;
this.DDL_Dis.DataSource = dt3;
this.DDL_Dis.DataTextField = "DistrictName";
this.DDL_Dis.DataValueField = "DistrictID";
this.DDL_Dis.DataBind();
}
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
table2.Visible = CheckBox1.Checked;
}
<ContentTemplate>
<asp:DropDownList ID="DDL_PRO" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDL_PRO_SelectedIndexChanged"
Width="150px">
</asp:DropDownList>
<asp:DropDownList ID="DDL_City" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDL_City_SelectedIndexChanged"
Width="150px">
</asp:DropDownList>
<asp:DropDownList ID="DDL_Dis" runat="server" Width="150px">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>