DropDownList DropDownList1=(DropDownList)Toolbar1.FindControl ("id");
DropDownList1.DataSource=dataset1.Tables[0].DefaultView ;
DropDownList1.DataTextField="text";
DropDownList1.DataValueField="value";
DropDownList1.DataBind ();

解决方案 »

  1.   

    不行啊。
    DropDownList DropDownList1=(DropDownList)Toolbar1.FindControl ("id");
    执行过后DropDownList1还是未定义。
    到DropDownList1.DataSource=dataset1.Tables[0].DefaultView 时
    出现如下错误 :未将对象引用设置到对象的实例
    帮忙啊。
      

  2.   

    將它改成
    if (DropDownList1!=null)
    DropDownList1.DataSource=dataset1.Tables[0].DefaultView 
      

  3.   

    不行,if (DropDownList1!=null)
    DropDownList1.DataSource=dataset1.Tables[0].DefaultView 
    就不执行下面的DropDownList1.DataSource=dataset1.Tables[0].DefaultView 看来是DropDownList DropDownList1=(DropDownList)Toolbar1.FindControl ("id");
    的问题,哪位大虾帮忙啊。