protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            MyWeb.Web.FillDDL(this.DropDownList1, "请选择", MyWeb.MyData.GetDBList("CodeTye"), "CodeName", "CodeTyeID");               
        }
    }
   protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.DropDownList1.SelectedIndex == 0)
        {
            this.DropDownList2.DataSource = null;
            this.DropDownList2.DataBind();
            return; 
        }
        string[,] FArr = new string[1, 4];
        FArr[0, 0] = "FKeyValue";
        FArr[0, 1] = this.DropDownList1.SelectedItem.Text;
        FArr[0, 2] = "1";
        FArr[0, 3] = "等于";
        DataTable CodeDT = MyWeb.MyData.GetDBList("Code", FArr, "CodeID", "1");
        MyWeb.Web.FillDDL(this.DropDownList2, "请选择", CodeDT, "FDispValue", "CodeID");
    }
其中:FKeyValuethis.DropDownList1.SelectedItem.Text都是汉字。要实现的意思就是,当this.DropDownList1.SelectedItem.Text选择值后自动在Code表里获取带有改文字的所有列表,用DropDownList2显示出来。

解决方案 »

  1.   

    页面显示错误,提示:在将 varchar 值 '地基与基础工程专业承包' 转换成数据类型 int 时失败。
      

  2.   

    发现你写法好奇怪,真没太明白为什么要写得那么复杂去实现那么简单的功能:
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            if (this.DropDownList1.SelectedIndex == 0) 
            { 
                  
                //选择值
                int SelectID=Convert.ToInt32(DropDownList1.SelectedValue);           //新建方法
                dataBind(SelectID)
            } 

    protect dataBind(int id)
    {
        利用id取得值dataset :ds
        datatable dt=ds.Table["XXXX"];
        DropDownList1. DataSource =dt;
        DropDownList2.DataBind(); 
        DropDownList1.SelectedItem="XXXX";
        DropDownList1.SelectedValue="XXXX";}不就是绑完在绑,换值接着绑吗?实在没看懂为什么要你那么写