在DropDownList1中,绑定select distinct JH from ah202_1,然后在DropDownList1中选择一个JH字段;之后在DropDownList2中绑定select TC from ah202_1 where JH='"+DropDownList1.SelectedItem.Text+"'; 请问高手怎么解决?要注意的是,存在一个刷新问题,有代码的请给代码,没代码的给个思路!在线等待急呀急

解决方案 »

  1.   

    autopostback=true
    在DropDownList1的selectedindexchange事件中写第二个DropDownList绑定
      

  2.   

    http://dev.csdn.net/develop/article/33/33880.shtm
      

  3.   

    http://community.csdn.net/Expert/topic/3344/3344832.xml?temp=.7325556
      

  4.   

    在Dropdownlist1的selectedindexchanged事件里给Dropdownlist2绑定
      

  5.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    if (!IsPostBack)
    {
    DataSet ds = new DataSet();
    ds.ReadXml(Server.MapPath("DataSource.xml"));
    for(int i = 0;i <ds.Tables[0].Rows.Count ;i++)
    {
    DataRow dr = ds.Tables[0].Rows[i];
    Want.Text += String.Format("Group[Groupcount++] = new Array(\"{0}\",\"{1}\",\"{2}\");\n", dr["v_Source"],dr["v_GroupName"].ToString(), dr["v_title"].ToString());
    if (SourceList1.Items.FindByText(dr["v_Source"].ToString()) == null)
    {
    SourceList1.Items.Add(dr["v_Source"].ToString());
    }
    }
    }
    }<%@ Page language="c#" Codebehind="TreeDropDownList.aspx.cs" AutoEventWireup="false" Inherits="TowDropDownList.TowDropDownList" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>TreeDropDownList</title>
    <meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <script language="javascript">
    var Wantcount;
    var Groupcount;
    Groupcount=0;
    Group = new Array();
    <asp:Literal id="Want" runat="server"></asp:Literal>
    function changelocation1(locationid)
    {
    document.submit.DirectionList1.length = 0;
    document.submit.WantList1.length = 0;
    var locationid=locationid;
    var i;
    var flag;
    var j;
    for (i=0;i<Groupcount; i++)
    {
    if (Group[i][0] == locationid)
    {
    flag = true;
    for (j =0;j<document.submit.DirectionList1.length;j++)
    if (document.submit.DirectionList1[j].value == Group[i][1])
    {
    flag = false;
    break;
    }
    if (flag)
    document.submit.DirectionList1.options[document.submit.DirectionList1.length]
    = new Option(Group[i][1], Group[i][1]);
    }
    }
    }
    function changelocation11(locationid, direction)
    {
    document.submit.WantList1.length = 0;
    var locationid=locationid;
    var i;
    var flag;
    var j;
    for (i=0;i<Groupcount;i++)
    {
    if (Group[i][0] == locationid && Group[i][1] == direction)
    {
        
    flag = true;
    for (j=0;j<document.submit.WantList1.length;j++)
    if (document.submit.WantList1[j].value == Group[i][2])
    {
    flag = false;
    break;
    }
    if (flag)
    document.submit.WantList1.options[document.submit.WantList1.length]
    = new Option(Group[i][2], Group[i][2]);
    }
    }
    } </script>
    </HEAD>
    <BODY ms_positioning="GridLayout">
    <form id="submit" method="post" runat="server">
    <TABLE style="Z-INDEX: 101; LEFT: 184px; POSITION: absolute; TOP: 144px">
    <TR>
    <TD style="WIDTH: 115px; HEIGHT: 17px" align="middle">求职意向:</TD>
    <TD style="HEIGHT: 17px"><asp:dropdownlist id="SourceList1" runat="server" DataTextField="v_source" DataValueField="v_source" onchange="changelocation1(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value);changelocation11(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value,document.submit.DirectionList1.options[document.submit.DirectionList1.selectedIndex].value)" Width="100px"></asp:dropdownlist><asp:dropdownlist id="DirectionList1" runat="server" DataValueField="v_GroupName" onchange="changelocation11(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value,document.submit.DirectionList1.options[document.submit.DirectionList1.selectedIndex].value)" Width="100px"></asp:dropdownlist><asp:dropdownlist id="WantList1" runat="server" DataValueField="v_title" Width="100px"></asp:dropdownlist></TD>
    </TR>
    </TABLE>
    </form>
    <script language="javascript">
    changelocation1(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value);
    changelocation11(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value,document.submit.DirectionList1.options[document.submit.DirectionList1.selectedIndex].value)
    </script>
    </BODY>
    </HTML><DataSource>
    <Data>
    <v_Source>计算机类</v_Source>
    <v_GroupName>软件</v_GroupName>
    <v_title>程序员</v_title>
    </Data>
    <Data>
    <v_Source>计算机类</v_Source>
    <v_GroupName>软件</v_GroupName>
    <v_title>系统分析员</v_title>
    </Data>
    <Data>
    <v_Source>计算机类</v_Source>
    <v_GroupName>软件</v_GroupName>
    <v_title>项目经理</v_title>
    </Data>
    <Data>
    <v_Source>计算机类</v_Source>
    <v_GroupName>硬件</v_GroupName>
    <v_title>网络工程师</v_title>
    </Data>
    <Data>
    <v_Source>计算机类</v_Source>
    <v_GroupName>硬件</v_GroupName>
    <v_title>计算机维护</v_title>
    </Data>
    <Data>
    <v_Source>计算机类</v_Source>
    <v_GroupName>数据库</v_GroupName>
    <v_title>数据库开发</v_title>
    </Data>
    <Data>
    <v_Source>计算机类</v_Source>
    <v_GroupName>数据库</v_GroupName>
    <v_title>数据库管理</v_title>
    </Data>
    <Data>
    <v_Source>行政/管理类</v_Source>
    <v_GroupName>行政</v_GroupName>
    <v_title>文秘</v_title>
    </Data>
    <Data>
    <v_Source>行政/管理类</v_Source>
    <v_GroupName>行政</v_GroupName>
    <v_title>助理</v_title>
    </Data>
    <Data>
    <v_Source>行政/管理类</v_Source>
    <v_GroupName>管理</v_GroupName>
    <v_title>总经理</v_title>
    </Data>
    <Data>
    <v_Source>行政/管理类</v_Source>
    <v_GroupName>管理</v_GroupName>
    <v_title>部门经理</v_title>
    </Data>
    <Data>
    <v_Source>行政/管理类</v_Source>
    <v_GroupName>管理</v_GroupName>
    <v_title>总监</v_title>
    </Data>
    </DataSource>
      

  6.   

    要注意的是,存在一个刷新问题???---------------------
    楼主的意思究竟是可不可以刷新呢?
    如果可以,楼上的已经说全了
    Dropdownlist1.autopostback属性设为true
    private void DropDownList1_selectedindexchange(...)
    {事件中写第二个DropDownList绑定}如果不可以刷新就比较麻烦,可以把第二下拉框的数据全部取出来变成一个脚本里的数组,用脚本进行查询;或者用脚本调用webservice的方法去做数据库查询
      

  7.   

    将第一个DropDownList的AutoPostBack设为True在SelectedIndexChanged事件里得到SelectedItem.Value,然后在第二个DropDownList绑定数据源的同时,循环绑定数据,并且判断if(dropdownlist2.Items[i].Value==dropdownlist1.SelectedItem.Value)
    dropdownlist2.SelectedIndex=i
      

  8.   

    http://www.cnblogs.com/fecitsky/articles/35827.aspx
      

  9.   

    将第一个DropDownList的AutoPostBack设为True在
      

  10.   

    将第一个DropDownList的AutoPostBack设为True在
                 --欧阳如枫[^_^(笑一个)]
    〔努力拼搏〕〔拼搏奋斗〕〔奋斗进取〕〔进取努力〕
                    愿你和我一样快乐。
      

  11.   

    to:Eddie005(暴走005) 
    对你的想法比较感兴趣,能具体的谈谈吗?现在的问题是我选第一个DropDownList里的数据,就刷新了页面,又回到原始状态,请赐教!
      

  12.   

    在Page_Load()中,帮定dropdownlist1
    这样,他就不会回到原始状态了
      

  13.   

    设置autopostback=true,然后激发选项改变事件
      

  14.   

    下面是我的代码,不知道什么地方出问题了,刷新问题一直存在!using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.OleDb;
    using Coremis.AllPages.dboperation;
    using HFSecurityLib;
    namespace Coremis.AllPages.operajing
    {
    /// <summary>
    /// ImageOper 的摘要说明。
    /// </summary>
    public class ImageOper : System.Web.UI.Page
    {
    private DbConnector m_DbConnector=null;
    private string Global_GroupName="";
    private string m_strCurrJH="";
    private string m_strAllJH="";
    protected System.Web.UI.WebControls.DropDownList DropdownlisttongCi;
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.Label Label2;
    protected System.Web.UI.WebControls.Button BtBrower;
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.TextBox TextBox2;
    protected System.Web.UI.WebControls.DropDownList DropDownListjingName;


    private void Page_Load(object sender, System.EventArgs e)
    { m_DbConnector=DbConnector.CreateInstance();
    m_DbConnector.ConnectToOracle(Session); if(!Page.IsPostBack)
    {
    if(Request["alljh"]==null || Request["currjh"]==null) 
    {
    Response.Write("参数传递错误!");
    Response.End();
    }
    try
    {
    HFSecurityLib.WebUserClass  Global_UserObject=(WebUserClass)Session["WebUserObject"];
    string Global_UserName=Global_UserObject.Account;//Session("LoginUserName");
    string Global_UserPass=Global_UserObject.Password;//Session("LoginUserPass");
    if (Global_UserObject==null) Response.Redirect("../ErrPage.asp?ErrorMsg=用户已经超时,请重新登陆");
    if (Global_UserObject.Status<=0)
    {
    Response.Redirect("../ErrPage.asp?ErrorMsg=您的连结被管理员切断了");
    }
    if(Global_UserObject.Group!=null)
    {
    Global_GroupName=Global_UserObject.Group.Name;
    }
    }
    catch(Exception err)
    {
    Response.Redirect("../ErrPage.asp?ErrorMsg=用户已经超时,请重新登陆");
    } m_strAllJH=Request["alljh"].ToString();
    m_strCurrJH=Request["currjh"].ToString();
    DropDownListjingName.AutoPostBack=true;
    CreateToolBarjingName();
    }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.DropDownListjingName.SelectedIndexChanged += new System.EventHandler(this.DropDownListjingName_SelectedIndexChanged);
    this.BtBrower.Click += new System.EventHandler(this.BtBrower_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void CreateToolBarjingName()
    {
    DataSet ds=new DataSet();
    string[] strTempArray=m_strAllJH.Split('|');
    foreach(string strTemp in strTempArray)
    {
    OleDbConnection cn=m_DbConnector.GetConnection();
    string strSQL="select distinct JH from ah202_1 where JH='"+strTemp+"'";
    OleDbDataAdapter myAdapter=new OleDbDataAdapter(strSQL,cn);
    myAdapter.Fill(ds);
    }
    DropDownListjingName.DataSource=ds.Tables[0].DefaultView;
    DropDownListjingName.DataTextField="JH";
    DropDownListjingName.DataValueField="JH";
    DropDownListjingName.DataBind();
    }
    private void DropDownListjingName_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    OleDbConnection cn=m_DbConnector.GetConnection();
    DataSet ds=new DataSet();
    OleDbDataAdapter adapter=new OleDbDataAdapter("select distinct TC from AH202_1 where jh='" +DropDownListjingName.SelectedValue.ToString()+ "'",cn);
    adapter.Fill(ds,"adapter");
    DropdownlisttongCi.DataSource=ds.Tables["adapter"].DefaultView;
    DropdownlisttongCi.DataTextField="TC";
    DropdownlisttongCi.DataValueField="TC";
    DropdownlisttongCi.DataBind();
    } private void BtBrower_Click(object sender, System.EventArgs e)
    {
        DropdownlisttongCi.AutoPostBack=true;
    string strsd="";
    string strSql="select sd1 from AH202_1 where tc='"+DropdownlisttongCi.SelectedItem.Text+"'";
    DataSet ds=m_DbConnector.GetDataSet(strSql);
    if(ds.Tables[0].Rows.Count>=1)
    {
    for(int i=0;i<ds.Tables[0].Rows.Count-1;i++)
    {
    strsd=ds.Tables[0].Rows[0][0].ToString();
    break;
    }
    }
    TextBox1.Text=DropDownListjingName.SelectedItem.Text.ToString();
    TextBox2.Text=strsd;
    }
    }
    }
      

  15.   

    俺才写过,给你代码,呵呵
    private void drop_dq_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    this.drop_sx.Items.Clear();
    DataSet dst=new DataSet();
    gl.viewnum(dst,this.drop_dq.SelectedItem.Text);
    gl.viewsx(dst,dst.Tables[0].Rows[0]["id"].ToString());
    for(int i=0;i<dst.Tables[1].Rows.Count;i++)
    {
    this.drop_sx.Items.Add(dst.Tables[1].Rows[i]["regionname"].ToString());
    }
    }
    我都懒的改了,先要把第一个的autopostback设置为TRUE,不然不会立即触发事件
    然后再在它的SelectedIndexChanged事件里面写代码,呵呵
      

  16.   

    在LOAD里面加上这句:
    dropdownlist.autopost=true
      

  17.   

    你该不是把EnableViewState设为False了吧?如果是False的话,就可能每次刷新,你选中的内容又会变为初始值
      

  18.   

    以上各位说的我试了,结果出来了!但现在还存在一个问题,当我把一个数组中的值赋给DropDownList1时,却选不中DropDownList1中的数据,刷新回到原始状态,代码如下:
        
    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!Page.IsPostBack)
    {
      CreateDropDownList1();
    }private void CreateDropDownList1()
    {
    string[] strTempArray=m_strAllJH.Split('|');
    ArrayList arr=new ArrayList();
    foreach(string strTemp in strTempArray)
    {
         arr.Add(strTemp);
    }
    DropDownList1.DataSource=arr;
    DropDownList1.DataBind();
    }
    请各位再次帮帮忙!马上给分。。
      

  19.   

    问题已经解决了,多谢大家提出宝贵的意见,最主要的问题是把web.config配置文件改成
    <globalization
         requestEncoding="gb2312"
         responseEncoding="gb2312"
    />
    因为我在传值过程中使用了中文,所以,当把中文绑定到DropDownList中时,就会出现选择时,刷新到原始状态。并不是简单的数据绑定。