我现有DropDownList和textbox1两个控件,我想根据DropDownList中选取的值,在数据库中查找出相对应的值在textbox1中显示,如何在C#中实现,请高手赐教,谢谢。
如在DropDownList选择1111,在textbox1中显示bbbb。
表A
A     B
1111  bbbb
2222  cccc

解决方案 »

  1.   

    Dropdownlist有个SelectedChanged事件,在里面根据你选择的Dropdownlist的值,来显示相应的值
      

  2.   

    是OnSelectedIndexChanged事件吗?能给个具体的写法我吗?谢谢
      

  3.   

    用Dropdownlist的SelectIndexChange事件也行
    步骤如下:
    首先确定Dropdownlist中有数据,在属性Item(集合)添加数据;
    选择Dropdownlist属性中的AutoPostBack改成True;
    在Dropdownlist的SelectIndexChange事件中写如下代码:
    textbox1.Text=Dropdownlist.SelectedItem.Value;具体参考
    http://www.bcbbs.net/News/Content75313.aspx
      

  4.   

    如果我已经建设了一个工厂
    protected void BusSort_Changed(object sender, EventArgs e)
            {
                   string ft;
                string bsd;
                bsd = BusSortDwList.SelectedValue.Trim();
                DataSet ds = BLLFactory.tbBusTypeManage.Create().GetDataFList(bsd);
    }
    GetDataFList(bsd) 是一个得到结果值的公式,那我应该怎么写才对呢?
      

  5.   

    DataSet ds = BLLFactory.tbBusTypeManage.Create().GetDataFList(bsd);
    直接从DataSet(ds)中取出B字段的值传给textBox1就行了啊
     
      

  6.   

    protected void BusSort_Changed(object sender, EventArgs e)
            {
                string ft;
                string bsd;
                bsd = BusSortDwList.SelectedValue.Trim();
                DataSet ds = BLLFactory.tbBusTypeManage.Create().GetDataFList(bsd);
                ft = Convert.ToString(ds);
                TextBox1.Text = ft;
                      
            }这样写对吗?
      

  7.   

    当然不对啊,这样
    你ds的结构我不知道是怎样的?不知道怎么写?
    自己看看DataSet的用法
    DataTable dt=ds.Tables[0];private void PrintRows(DataSet dataSet)
    {
        // For each table in the DataSet, print the row values.
        foreach(DataTable table in dataSet.Tables)
        {
            foreach(DataRow row in table.Rows)
            {
                foreach (DataColumn column in table.Columns)
                {
                    Console.WriteLine(row[column]);
                }
            }
        }
    }看看DataSet和DataTable以及DataRow、DataColumn的用法,还有他们之间的关系
    http://msdn.microsoft.com/zh-cn/library/system.data.dataset.tables.aspx
    http://msdn.microsoft.com/zh-cn/library/system.data.datatable.rows.aspx
      

  8.   

    /// <summary>
            /// 获取燃料类型
            /// </summary>
            public DataSet GetDataFList(string strWhere)
            {
                string sqlByWhere;
                sqlByWhere = "select FuelType from [BusType] ";            if (strWhere != "" && strWhere != null)
                {
                    sqlByWhere += " where BusType='" + strWhere + "'";            }
                return this.visitor.ExecuteDataset(sqlByWhere);
            }我的ds里面是这样写的。
      

  9.   

    ft = Convert.ToString(ds.Tables[0].Rows[0][0]);
    TextBox1.Text = ft;