asp.net通过DropDownList绑定数据数据库实现级联怎么无效呢?代码如下:

前台:<asp:DropDownListID="school"runat="server"AutoPostBack="true"OnSelectedIndexChange... 前台:
<asp:DropDownList ID="school" runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="school_SelectedIndexChanged"
Height="20px" Width="109px">
</asp:DropDownList>
<asp:DropDownList ID="pro" runat="server" Height="20px"
Width="107px" >
</asp:DropDownList>
后台:
protected void Page_Load(object sender, EventArgs e)
{
this.results.Visible = false;
this.add2.Visible = false;
if(!IsPostBack)
{
string strConn = @"Data Source=. ;Initial Catalog=Stuadmin;Integrated
Security=True";
SqlConnection con = new SqlConnection(strConn);
string sql = "SELECT distinct [sname] FROM [pro]";
SqlDataAdapter school1 = new SqlDataAdapter(sql, con);
DataSet schools = new DataSet();
con.Open();
school1.Fill(schools);
this.school.DataSource = schools;
this.school.DataValueField = "sname";
this.school.DataTextField = "sname";
this.school.DataBind();
con.Close();
}
}
protected void school_SelectedIndexChanged(object sender, EventArgs e)
{
string strConn = @"Data Source=.;Initial Catalog=Stuadmin;Integrated
Security=True";
SqlConnection con = new SqlConnection(strConn);
string sql = "SELECT [pname] FROM [pro] WHERE sname='" +
this.school.SelectedValue.Trim() + "'";
SqlDataAdapter pro1 = new SqlDataAdapter(sql,con);
DataSet pros = new DataSet();
con.Open();
pro1.Fill(pros);
this.pro.DataSource = pros;
this.pro.DataValueField = "pname";
this.pro.DataTextField = "pname";
this.pro.DataBind();
con.Close();
}
展开
 我来答
tsuiweiwei
2012-08-08 · 超过10用户采纳过TA的回答
知道答主
回答量:36
采纳率:0%
帮助的人:17.6万
展开全部
看代码好像没问题,怎么个无效法?
画角连城
2012-08-09 · TA获得超过774个赞
知道小有建树答主
回答量:224
采纳率:0%
帮助的人:312万
展开全部
有两行代码改成这样:
this.school.DataSource = schools.Tables[0];

this.pro.DataSource = pros.Tables[0];
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式