Custom Treenodes in Treeview

S

SunSmile

Hi,
Iam a using a custom treeview control, taking an example from
http://fredrik.nsquared2.com/viewpost.aspx?PostID=299.

I have created two hyperlink's after each node in the treeview. When i click
on any one of the hyperlink's the selectednodechanged event of the custom
treeview control is not firing up.

My sample treenode is as below.

<<Some Text>> hyperlink1 hyperlink2

I am creating hyperlink1 and hyperlink2 as follows

protected override void RenderPostText(HtmlTextWriter writer)
{

writer.Write(" ");
writer.WriteBeginTag("A");
writer.WriteAttribute("href", "Treeview.aspx" );

writer.Write(">");
writer.Write("Reply");
writer.WriteEndTag("A");

writer.Write(" ");
writer.Write(" ");
writer.Write(" ");

writer.WriteBeginTag("A");
writer.WriteAttribute("href", "Treeview.aspx");
writer.Write(">");
writer.Write("Edit");
writer.WriteEndTag("A");
}

Any furthur comments and suggestions are welcome.
Thanks in advance.
 
K

Keith Patrick

For ease of coding, I'd recommend this instead:
HyperLink link = new HyperLink();
link.NavigateUrl = "TreeView.aspx";
link.Text = "Edit";
link.RenderControl(writer);

Are your treenodes showing URLs or are they javascript method calls? If
they are the former, then your tree is in navigate mode, and thus the
selection events won't fire. You can change the mode by altering the
binding for that particular node depth (via the DataBindings child element
for the TreeView)
 
S

SunSmile

Thanks Patrick,
Can you tell me in more detail how to change the navigate mode. Also
how do i remove the hyperlinks for the Nodes (Not the two hyperlinks i have
added)and make them as simple text. Is it possible to do so?

Thanks,
SunSMile
 
K

Keith Patrick

Yeah, basically it's a matter of the databinding. This is an example of a
databinding that sets the 3rd nest level of a tree I have bound to a
SiteMapDataSource (hence the field names of "url" and "title") to selection
mode (as you can see by the URL, which is a call do doPostback):
<DataBindings>
<asp:TreeNodeBinding Depth="2"
NavigateUrlField=""
DataMember=""
TextField="Title"
ValueField="url" />
</DataBindings>

The key to taking out the URLs lies with setting the data and navigateURL
members to String.Empty. The ValueField determines what the CommandArgument
is going to be (and is passed in as a param to doPostback)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top