我新建了一个用户控件UCDropDownList,里面放了一个DropDownList..
请问如何做到我在使用UCDropDownList时直接在aspx页里面给DropDownList添加ListItem..
如:
<uc1:UCDropDownList ID="a" runat="server">
<asp:ListItem Text="a" Value="0"></asp:ListItem>
<asp:ListItem Text="b" Value="1"></asp:ListItem>
</uc1:UCDropDownList>

解决方案 »

  1.   

    把要显示的数据,绑定到DropDownList中
      

  2.   

    在用户控件 后台代码中写一个public 方法 添加ListItem
    在页面中需要给DropDownList添加ListItem 时 就调用 UCDropDownList ID . 方法来调用所写的方法
      

  3.   


    可以详细一点不?我不是在要在后台给DropDownList赋值哦.. 
    我是想在页面上直接添加ListItem..
      

  4.   

     UserControl c = Page.FindControl("WebUserControl1") as UserControl;//找到用户控件
            if (c != null)
            {
                TextBox tb = c.FindControl("TextBox1") as TextBox;//找到用户控件中的控件
                if (tb != null)
                {
                    tb.Text = "找到";
                }
               
            }
    以上可做参考,其实上面是找用户控件中的textbox,道理是一样的,找到后,在aspx.cs中怎么处理都行了就。