我在userc自定义控件中的   DropDownList 我想在宿主页面让里面的某一个值为选中奖态;
请问如何实现呢?
  例:
DropDownList 默认值1
2
3
4宿主页面:
当读取数据库时让DropDownList.Selected=ds.tables["aa"].rows[0]["aaa"].Tostring();
请问如何实现

解决方案 »

  1.   

    DropDownList.Items.FindByText( ds.tables["aa"].rows[0]["aaa"].Tostring() ).Selected = true;
      

  2.   

    我是在宿主页面里的啊,同志.能用下面这句代码吗?DropDownList.Items.FindByText( ds.tables["aa"].rows[0]["aaa"].Tostring() ).Selected = true;
      

  3.   

    public class aaa : System.Web.UI.UserControl
    {
       public string DropDownValue
      {
         get{return DropDownList1.SelectedValue;}
         set{DropDownList1.SelectedValue = value;}
       } 
      .........
      

  4.   

    自定义控件加一个属性值来设置他某一项的选定状态,
    在主页面的load中加入自定义控件赋值语句
      

  5.   

    在主页面用
    DropDownList ddlst = (DropDownList)this.WebUserControl1.FindControl("DropDownList1");也可以实现,但绝不是lz说的所谓“更好的方法” ---- 性能低并且编程思想不好