本来想选择一个项时,触发BM_SelectedIndexChanged,下面的listbox跟着变化.但不知为何总不能触发事件.请问各位是什么原因?
两个文件的源码如下,由于过长,省略号省略了一些.--------webform1.aspx-------------------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>tree</title>
......
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<TABLE id="Table1" borderColor="lightsteelblue" height="182" cellSpacing="0" cellPadding="0" width="456" border="1">
    <TR>
        <TD bgColor="steelblue" colSpan="3">选择参考人员</TD>
    </TR>
    <TR>
    <TD><asp:dropdownlist id="BM" runat="server" Width="136px" AutoPostBack="True"></asp:dropdownlist></TD>
    <TD colSpan="3" height="8"><select id="BM2" style="WIDTH: 144px" runat="server"></select></TD>
    </TR>
    <TR>
<TD><asp:listbox id="ListBox1" runat="server" Width="184px" Height="102px"></asp:listbox></TD>
<TD><INPUT id="ToRight" type="button" value=">" name="ToRight" runat="server"><BR>
<BR>
<INPUT id="ToLeft" type="button" value="<" name="ToLeft" runat="server"><BR>
<BR>
<INPUT id="AllToLeft" type="button" value="<<" name="AllToLeft" runat="server"></TD>
       <TD><asp:listbox id="ListBox2" runat="server" Width="184px" Height="102px"></asp:listbox></TD>
    </TR>
    <TR>
        <TD colSpan="3" height="26"><INPUT id="submit" type="button" value="提 交" name="submit" runat="server">&nbsp;<INPUT id="cancel1" type="button" value="取 消" name="Button1" runat="server"></TD>
    </TR>
    </TABLE>
    <asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 88px; POSITION: absolute; TOP: 280px" runat="server">Label</asp:Label></FONT></form>
</body>
</HTML>/*---------webform.aspx.cs-----------------------using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace testsys
{
/// <summary>
/// tree 的摘要说明。
/// </summary>
  public class tree : System.Web.UI.Page
  {
    ........

    private void Page_Load(object sender, System.EventArgs e)
    {
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
         {
  bindSelect();
  string sqlstr = "select name,no from rs where sbbc='A01' and ryzt not in(1)";
  string strWhere = "";
  string strOrder = " order by bmno,no";
  bindListBox(sqlstr,strWhere,strOrder);
}
    }  // 从数据库BM表选择两个字段Name,no绑定到BM
  private void bindSelect()
  {
  ...........
  }  //bind left ListBox
  private void bindListBox(string sqlstr,string strWhere,string strOrder)
  {
    SqlConnection myconn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["strcon"]);
    SqlDataAdapter mycomm = new SqlDataAdapter(sqlstr+strWhere+strOrder,myconn);
    DataSet ds = new DataSet();
    mycomm.Fill(ds,"rs");
    DataView dv = ds.Tables["rs"].DefaultView;
    this.ListBox1.DataSource = dv;
    this.ListBox1.DataTextField = "name";
    this.ListBox1.DataValueField = "no";
    this.ListBox1.DataBind();
    myconn.Close();
  }  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
  }

  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {    
    this.BM.SelectedIndexChanged += new System.EventHandler(this.BM_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load);
  }
  #endregion  private void BM_SelectedIndexChanged(object sender, System.EventArgs e)
  {
    string str1="select name,no from rs where sbbc='A01' and ryzt not in(1)";
    string str2="and bmno like '%" + this.BM.SelectedValue +"'";
    string str3=" order bmno,no";
    this.Label1.Text = this.BM.SelectedItem.Value.ToString();
    bindListBox(str1,str2,str3);
  }
}

解决方案 »

  1.   

    这样做会比较闪可以考虑用javascript
      

  2.   

    AutoPostBack已经设为True了,还是没有反应...
    用javascript,dropdownlist是从数据库里动态选出来的,不会做.
      

  3.   

    <TR>
            <TD bgColor="steelblue" colSpan="3">选择参考人员</TD>
        </TR>
        <TR>
        <TD><asp:dropdownlist id="BM" runat="server" Width="136px" AutoPostBack="True"></asp:dropdownlist></TD>
        <TD colSpan="3" height="8"><select id="BM2" style="WIDTH: 144px" runat="server"></select></TD>
        </TR>AutoPostBack已经设为True了,还是不行.
    好奇怪哦!又找不出什么错误.
      

  4.   

    数据都存储在数据库里面,是原来就有的,我只是引用里面的数据.
    比如说部门,要是在其它删除部门或新增部门,都不会影响到我的数据.
    我想用一个dropdownlist,两个ListBox(一个在左边/leftListBox,一个在右边/rightListBox)
    当我不选部门(BM)时,leftListBox显示所有部门所有的人员,当我选一个部门时,leftListBox就显示这个部门下的人员.可是那个事件怎么也触发不了.
      

  5.   

    像这样子:
    --------------------------------
    |---请选择部门--^|
    --------------------------------
     leftListBox        rightListBox  
    |张三       |  >   |            |
    |李四       |  <   |            |
    |王五       |  >>  |            |
    |陆六       |  <<  |            |
      

  6.   

    这样从后台取可能不是好方法吧
    用javascript
      

  7.   

    请问用javascript怎么实现???
      

  8.   

    AutoPostBack = "true"
    会刷新页面的
      

  9.   

    private void Page_Load(object sender, System.EventArgs e)
        {
    // 在此处放置用户代码以初始化页面
    if(!IsPostBack)
             {
      bindSelect();
      string sqlstr = "select name,no from rs where sbbc='A01' and ryzt not in(1)";
      string strWhere = "";
      string strOrder = " order by bmno,no";
      bindListBox(sqlstr,strWhere,strOrder);
    }
        }
    有问题bindListBox(sqlstr,strWhere,strOrder);应该放在
    if(!IsPostBack)
             {}
    外边