[code=C#<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server">
</asp:ScriptManager>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedValue"/>
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdatePanel1" EventName="Triggers" />
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
][/code]using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = DB.creatBm256();
con.Open();
SqlCommand cmd = new SqlCommand("select * from bm_province", con);
SqlDataReader sdr = cmd.ExecuteReader();
this.DropDownList1.DataSource = sdr;
this.DropDownList1.DataTextField = "province";
this.DropDownList1.DataValueField = "proId";
this.DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = DB.creatBm256();
con.Open();
SqlCommand cmd = new SqlCommand("select * from bm_city where proId=" + DropDownList1.SelectedValue, con);
SqlDataReader sdr = cmd.ExecuteReader();
this.DropDownList2.DataSource = sdr;
this.DropDownList2.DataTextField = "city";
this.DropDownList2.DataValueField = "cityId";
this.DropDownList2.DataBind();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = DB.creatBm256();
con.Open();
SqlCommand cmd = new SqlCommand("select * from bm_county where cityId=" + DropDownList2.SelectedValue.ToString(), con);
SqlDataReader sdr = cmd.ExecuteReader();
this.DropDownList3.DataSource = sdr;
this.DropDownList3.DataTextField = "county";
this.DropDownList3.DataValueField = "countyId";
this.DropDownList3.DataBind();
}
}
enentname那老是提示错,高手给指点下呗!
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server">
</asp:ScriptManager>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedValue"/>
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdatePanel1" EventName="Triggers" />
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
][/code]using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = DB.creatBm256();
con.Open();
SqlCommand cmd = new SqlCommand("select * from bm_province", con);
SqlDataReader sdr = cmd.ExecuteReader();
this.DropDownList1.DataSource = sdr;
this.DropDownList1.DataTextField = "province";
this.DropDownList1.DataValueField = "proId";
this.DropDownList1.DataBind();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = DB.creatBm256();
con.Open();
SqlCommand cmd = new SqlCommand("select * from bm_city where proId=" + DropDownList1.SelectedValue, con);
SqlDataReader sdr = cmd.ExecuteReader();
this.DropDownList2.DataSource = sdr;
this.DropDownList2.DataTextField = "city";
this.DropDownList2.DataValueField = "cityId";
this.DropDownList2.DataBind();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = DB.creatBm256();
con.Open();
SqlCommand cmd = new SqlCommand("select * from bm_county where cityId=" + DropDownList2.SelectedValue.ToString(), con);
SqlDataReader sdr = cmd.ExecuteReader();
this.DropDownList3.DataSource = sdr;
this.DropDownList3.DataTextField = "county";
this.DropDownList3.DataValueField = "countyId";
this.DropDownList3.DataBind();
}
}
enentname那老是提示错,高手给指点下呗!
解决方案 »
- asp.net 多线程问题,页面开了一个工作线程,工作线程向页面线程汇报进度,然后页面线程向client输出当前信息, 如何实现?
- OWC访问Analysis Services的问题
- Javascript 给Panel下所有Div加样式
- MSComm.OCX控件串口用脚本通讯问题
- 问一个比较基础的问题
- 关于asp.net开发B/S应用系统的思索和讨论,欢迎有此开发经验的同仁进来聊聊:)
- 如何对DATASET的列取别名?
- 为什么字段颠倒写结果不一样
- easyui grid绑定不上数据
- 如何在datagrid内动态创建控件并响应事件?
- 网站的起始动画是怎么链接的
- display中的static|dymatic|none这三个属性有什么区别?
分别为AsyncPostBackTrigger和PostBackTrigger,
AsyncPostBackTrigge用来指定某个服务器端控件以及其将触发的服务器端事件作为该UpdatePanel的异步更新触发器,它需要设置的属性有控件ID和服务端控件的事件;
PostBackTrigger用来指定在UpdatePanel中的某个服务端控件,它所引发的回送不使用异步回送,而仍然是传统的整页回送。
2、楼主可以这样试试:
<Triggers>
<asp:AsyncPostbackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged"/>
<asp:AsyncPostbackTrigger ControlID="DropDownList2" EventName="SelectedIndexChanged"/>
</Triggers>
虽然是不刷新 但但选择的时候局部还是会小闪一下,感觉不是很爽 所以后来就自己写ajax了