江湖救急。dropdownlist中的SelectedIndexChanged事件不可用是怎么回事啊?
要实现的功能是这样的在一个dropdownlist中选择施工单位,在第二个dropdownlist中显示与之对应的施工地点,且这两个控件都是绑定数据库的。也就是联动。
方案一与遇到的问题:
代码如下:
dropdownlist1:
<asp:Label ID="Label4" runat="server" Text="三违单位" CssClass="lable"></asp:Label>
<asp:DropDownList ID="sdwmc" runat="server" CssClass="dropdownlist"
Width="100px" onselectedindexchanged="sdwmc_SelectedIndexChanged"
>
</asp:DropDownList>
dropdownlist2:
<asp:Label ID="lable_s" runat="server" Text="施工地点" CssClass="lable"></asp:Label>
<asp:DropDownList ID="s_sgdd" runat="server" CssClass="dropdownlist"
onselectedindexchanged="s_sgdd_SelectedIndexChanged">
</asp:DropDownList>
cs文件:
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 Model;
using BLL;
using DAL;
using SqlHelpe;
namespace WebApplication1
{
public partial class sanw : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BLL_dwxx dwxx=new BLL_dwxx();
DataTable dt = new DataTable();
dt = dwxx.SelectAll();
//绑定施工单位
this.sdwmc.DataSource = dt;
this.sdwmc.DataTextField = "dwmc";
this.sdwmc.DataBind();
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged1(object sender, EventArgs e)
{
}
protected void s_sgdd_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void sdwmc_SelectedIndexChanged(object sender, EventArgs e)
{
//绑定施工地点
string sgdw = sdwmc.SelectedItem.Text;
BLL_dwddxx dwddxx = new BLL_dwddxx();
DataTable dt1 = new DataTable();
dt1 = dwddxx.selectdd(sgdw);
this.s_sgdd.DataSource = dt1;
this.s_sgdd.DataTextField = "sgdd";
this.s_sgdd.DataBind();
}
protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
其中可以确定:BLL_dwddxx dwddxx = new BLL_dwddxx();
DataTable dt1 = new DataTable();
dt1 = dwddxx.selectdd(sgdw);
this.s_sgdd.DataSource = dt1;
this.s_sgdd.DataTextField = "sgdd";
this.s_sgdd.DataBind();
绑定过程没有错误。
问题:当点击dropdownlist1时,dropdownlist2没反应,根据调试知道“protected void sdwmc_SelectedIndexChanged(object sender, EventArgs e)
”事件没执行,请问这是什么原因?,应该怎样解决。
方案二与遇到问题:
在dropdownlist1也就是“sdwmc”中加入属性“AutoPostBack="True" ”,也就是
<asp:Label ID="Label4" runat="server" Text="三违单位" CssClass="lable"></asp:Label>
<asp:DropDownList ID="sdwmc" runat="server" CssClass="dropdownlist"
Width="100px" onselectedindexchanged="sdwmc_SelectedIndexChanged" AutoPostBack="True"
>
</asp:DropDownList>
并且在<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" AutoEventWireup="true" CodeBehind="sanw.aspx.cs" Inherits="WebApplication1.sanw" EnableEventValidation="false" %>
中加入EnableEventValidation="false",不然产生错误“回发或回调参数无效”
之后,在第二个dropdownlist(s_sgdd)中出现了与之相应的项,但问题是“无论怎样在第一个dropdownlist(sdwmc)中,只能选定第一个值(采煤一区),当选定第二个值(采煤二区)时,还是回到第一个值(采煤一区),好像是自动刷新了,又成了第一个值,”,请问这是什么原因?应该怎样解决?
另外请问,错误“回发或回调参数无效”除了]EnableEventValidation="false"之外,还有其它的方法吗?
有劳各位大侠了。