DataSet ds1 = DB.RunProcReturn("select * from tb_sortA", "tb_sortA");
            DropDownList1.DataSource = ds1;
            DropDownList1.DataValueField = "sortname";
            DropDownList1.DataTextField = "sortname";
            DropDownList1.DataBind();
            ds1.Dispose();
            DropDownList1.SelectedValue = ds.Tables[0].Rows[0]["sortA"].ToString();不知道为什么已经赋值了,但DropDownList里的值还是第一个???

解决方案 »

  1.   

    什么意思  ds.Tables[0].Rows[0]这不是第一个数据吗,都是0索引
      

  2.   

     
    ds.Tables[0].Rows[0]是一个数据...
    如:
    ds1分别是:红、绿、蓝
    ds.Tables[0].Rows[0]是:绿想要DropDownList1初始化时值为:绿
    是这个意思.....
      

  3.   

    不明白你的意思,如果说你是想让他选中,就设置selectindex
      

  4.   

    DropDownList1.Items.FindByValue(ds.Tables[0].Rows[0]["sortA"].ToString()).Selected = true;
      

  5.   

    或者:
    DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(ds.Tables[0].Rows[0]["sortA"].ToString()));