我是个AJAX的三级联动 的省,市、县下拉框。现在我想让它默认显示的是从数据库中读取到的值,而不是默认的第一值。
 public void bindclass()
        {
            this.DropDownList1.DataSource = AjaxMethod.GetProvinceList();            this.DropDownList1.DataTextField = "PROVINCESNAME";
            this.DropDownList1.DataValueField = "CODE";
            this.DropDownList1.DataBind();
            this.DropDownList1.Items.Insert(0, new ListItem("请选择省", "0"));
            model = bll.GetModel(int.Parse(Request.Params["id"]));
            this.DropDownList1.SelectedValue = model.o_Province;//默认显示数据库中的值            this.DropDownList1.Attributes.Add("onchange", "cityResult();");
            this.DropDownList2.Attributes.Add("onchange", "areaResult();");            this.Introdry_1.DataSource = AjaxMethod.GetIntrod_1();
            Introdry_1.DataTextField = "GB_SortName";
            Introdry_1.DataValueField = "Id";
            Introdry_1.DataBind();
            this.Introdry_1.Items.Insert(0, new ListItem("请选择行业", "0"));
            Introdry_1.Attributes.Add("onclick", "Introd_2();");        }
这是我的代码,   this.DropDownList1.SelectedValue = model.o_Province;//默认显示数据库中的值这样写的不起作用、

解决方案 »

  1.   

    设置DropDownList1.SelectValue等于你想显示那个对象的ID值 , 尼玛这么简单的问题你也问 - -。
      

  2.   

    this.DropDownList1.DataBind(); 放到 SelectedValue 代码之后
      

  3.   

    通过在项里找从数据库中得到的某一个值,然后设置被选中即可。this.DropDownList1.Items.FindByText(model.o_Province).Selected = true;//默认显示数据库中的值this.DropDownList1.Items.FindByValue(model.o_Province).Selected = true;//默认显示数据库中的值
      

  4.   

    设置DropDownList1.SelectValue等于你想显示那个对象的ID值 , 尼玛这么简单的问题你也问 - -。自以为很屌的家伙,太他妈的垃圾了,你要会你就回答,不会就算,不要在这里屌,屌什么屌,估计你是他妈的什么都不懂的垃圾!