Click here to Skip to main content
15,923,142 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
i have a treeview control which binds all folders and files in my application like below
ASP.NET
<asp:TreeView ID="tvFolders" runat="server">
                              <HoverNodeStyle Font-Underline="false" ForeColor="#5555DD" />
                              <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px"
                                  ImageUrl="~/images/childfolder.png" NodeSpacing="0px" VerticalPadding="0px" />
                              <ParentNodeStyle Font-Bold="False" ImageUrl="~/images/childfolder.png" />
                              <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"
                                  VerticalPadding="0px" />
                              <LeafNodeStyle />
                          </asp:TreeView>


i need two buttons at each leafnode as download,delete. if i click those buttons respective actions should done for respective node(file).
for this i have binded my treeview like below
C#
foreach (string folder in Directory.GetDirectories(Server.MapPath("~/")))
            {
                string filename = Path.GetFileName(folder);
                if (filename.StartsWith("FY"))
                {
                    TreeNode tn = new TreeNode();
                    tn.Text = filename;
                    tn.Target = "_blank";
                    tvFolders.Nodes.Add(tn);

                    foreach (string innerfolder in Directory.GetDirectories(folder + "/"))
                    {
                        TreeNode intn = new TreeNode();
                        intn.Text = Path.GetFileName(innerfolder);
                        intn.Target = "_blank";
                        tn.ChildNodes.Add(intn);

                        DirectoryInfo directory = new DirectoryInfo(innerfolder);
                        FileInfo[] files = directory.GetFiles("*");

                        foreach (FileInfo file in files)
                        {
                            StringBuilder nodeText = new StringBuilder();
                            nodeText.Append(@"<table border="" 0="" cellpadding="" cellspacing=""><tr><td>");
                            nodeText.Append(@"<a style="" href="#" hold=" /&gt;                            nodeText.Append(@"> ").Append(file.Name).Append("</a>");
                            nodeText.Append(@"</td><td>");
                            nodeText.Append(@"</td><td>");
                            //nodeText.Append(@"&nbsp;&lt;input  önclick='return confirm('Are you sure want to delete this file?');' type='image' height='20px' height='20px'");
                            nodeText.Append(@"&nbsp;&nbsp;&nbsp;<a href="#">&lt;input id='filedownload' title='Download' type='image' height='10px' height='10px' src='images/download.png' /&gt;</a>&nbsp;&nbsp;");
                            nodeText.Append(@"&nbsp;<a href="#">&lt;input id='filedelete' type='image' title='Delete' height='10px' height='10px' ;' src='images/delete_node.png' /&gt;</a>");

                            nodeText.Append(@"</td></tr></table><a href="#">");
                            TreeNode file1 = new TreeNode();
                            //file1.Text = Path.GetFileName(file.Name);
                            file1.Text = nodeText.ToString();
                            file1.Value = "File";
                            file1.Target = "_blank";

                            if (file.Extension == ".doc" || file.Extension == ".docx")
                                file1.ImageUrl = "~/images/wordicon.png";
                            else if (file.Extension == ".pdf")
                                file1.ImageUrl = "~/images/pdficon.png";
                            else if (file.Extension == ".xls" || file.Extension == ".xlsx")
                                file1.ImageUrl = "~/images/excelicon.png";
                            else
                                file1.ImageUrl = "~/images/fileimg.png";

                            intn.ChildNodes.Add(file1);
                        }
                    }
                }
            }


so now i am getting two input buttons for each leaf node.

the problem is i m unable to get postback event for that leafnode click. i tryed to do in javascript __dopostback but my page is having update panel, it may be effecting not to postback.
i dont knw.

How to get leaf node click event in code behind.

i also tryd writing window.open(respective file path); in download button. it also not working

pls help.

thanks advance.
Posted
Updated 12-Mar-13 1:24am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900