private void loadDropLis()
    {       
DropDListBigType.DataTextField = "ProductBigTypeName";
DropDListBigType.DataValueField = "ProductBigTypeId";
DropDListBigType.DataSource = typebll.GetAllList();
DropDListBigType.DataBind();   
DropDListSmalType.DataTextField = "ProductsTypeName";
DropDListSmalType.DataValueField = "ProductsTypeId";
DropDListSmalType.DataSource = typebll.GetSmallType(Convert.ToInt32(DropDListBigType.SelectedValue)).Tables[0];
DropDListSmalType.DataBind();  
   }
程序:
loadDropLis();调用绑定方法
DropDListBigType.SelectedValue = typebll.GetBigType(model.ProductsTypeId).Tables[0].Rows[0]["ProductBigTypeName"].ToString();报错但是string a=typebll.GetBigType(model.ProductsTypeId).Tables[0].Rows[0]["ProductBigTypeName"].ToString();可以取到值。前面我也绑定了?我想先把所有项加载出来。然后默认选中数据库中邪的项。希望指出原因。

解决方案 »

  1.   

    if(DropDListBigType.Items.FindByValue("")!=null){}
      

  2.   

    不明白
    if (DropDListBigType.Items.FindByValue("") != null)
            {
                DropDListBigType.SelectedValue = typebll.GetBigType(model.ProductsTypeId).Tables[0].Rows[0]["ProductBigTypeName"].ToString();
            }
    这样?
      

  3.   

    这种错误是表中数据有null或为空!!
      

  4.   

    DropDListBigType.DataBind();  
    DropDListBigType.Items[0].Selected=true;//加上一个默认值。
    因为你下面就使用 了DropDListBigType.SelectedValue
      

  5.   

    加上了,还是不行 
    DropDListBigType.DataTextField = "ProductBigTypeName";
                DropDListBigType.DataValueField = "ProductBigTypeId";
                DropDListBigType.DataSource = typebll.GetAllList();
                DropDListBigType.DataBind();
                DropDListBigType.Items[0].Selected = true;
      

  6.   

    DropDListBigType.SelectedValue = typebll.GetBigType(model.ProductsTypeId).Tables[0].Rows[0]["ProductBigTypeName"].ToString();打印
     typebll.GetBigType(model.ProductsTypeId).Tables[0].Rows[0]["ProductBigTypeName"].ToString();这个值并不在DropDListBigType的value列表内导致的
      

  7.   

    改成
    ListItem x = DropDListBigType.Items.FindByValue(typebll.GetBigType(model.ProductsTypeId).Tables[0].Rows[0]["ProductBigTypeName"].ToString())
    if(x!=null)
    x.Selected=true;