This is a migrated thread and some comments may be shown as answers.

Problem with Image button dynamic in radTreeView

1 Answer 48 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Francisco
Top achievements
Rank 1
Francisco asked on 11 Jun 2012, 03:31 PM
I have a problem.
I need to create a dynamic image button and assign the event "click"  on a node of a "treeview", the problem is that when you click the image button disappears and never calls the event "lkbEliminar_Click".
    ImageButton lkbEliminar = new ImageButton();
      lkbEliminar.ImageUrl = "~/images/delete.png";
       lkbEliminar.ToolTip = "Eliminar Documento";
        lkbEliminar.Click += new System.Web.UI.ImageClickEventHandler(lkbEliminar_Click);  
      nodoHijoMenor.Controls.Add(lkbEliminar);
         nodoHijoMayor.Nodes.Add(nodoHijoMenor);
 
  protected void lkbEliminar_Click(object sender, ImageClickEventArgs e)
        {
            string x = "asdas";
            x = x + "asdsa";
 
           }

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Jun 2012, 05:32 AM
Hi Francisco,

One suggestion is you can add a node template with an image button dynamically as follows.

C#:
public partial class treeview_dynamicImageButton : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        nodoHijoMayor.NodeTemplate = new TextBoxTemplate();
        base.OnInit(e);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RadTreeNode nodoHijoMenor = new RadTreeNode();
            nodoHijoMayor.Nodes.Add(nodoHijoMenor);
        }
        nodoHijoMayor.DataBind();
    }
}
class TextBoxTemplate : ITemplate
{
    public void InstantiateIn(Control container)
    {
        ImageButton lkbEliminar = new ImageButton();
        lkbEliminar.ImageUrl = "~/images/bullet5.jpg";
        lkbEliminar.Click += new ImageClickEventHandler(lkbEliminar_Click);
        container.Controls.Add(lkbEliminar);
    }
 
    void lkbEliminar_Click(object sender, ImageClickEventArgs e)
    {
        string x = "asdas";
        x = x + "asdsa";
    }
}

Hope this helps.

Thanks,
Princy.
Tags
TreeView
Asked by
Francisco
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or