开发者

creating TemplateControl in c#

开发者 https://www.devze.com 2023-01-02 15:22 出处:网络
i have a telerik menu control that can have an <ItemTemplate>. suppose i have : <telerik:RadMenuItem Text=\"Filter\" Value=\"Search\" >

i have a telerik menu control that can have an <ItemTemplate>.

suppose i have :

<telerik:RadMenuItem Text="Filter" Value="Search" > 
   <ItemTemplate> 
      <asp:TextBo开发者_开发百科x ID="TextBox1" runat="server""/> 
   </ItemTemplate> 
</telerik:RadMenuItem>

how can i dynamically create the textbox itemTemplate in code behind?


you could try this:

 class txtBox : ITemplate
 {
    public void InstantiateIn(System.Web.UI.Control container)
    {           
        System.Web.UI.WebControls.TextBox txt= new System.Web.UI.WebControls.TextBox();
        txt.ID = "123";         
        container.Controls.Add(txt);
    }
 } 

and then add it to the menu in this way:

    RadMenuItem i = new RadMenuItem();
    i.ItemTemplate = new SearchTextBox();
    RadMenu1.Items.Add(i);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号