Treeview Ctrl - adding an index/key

S

Schoo

I have a working MS treeview control (from the webcontrols.dll) that is fed
with an XML file and a working SelectedIndexChange procedure. I need to
display a list of names, but then pass an ID number through the
SelectedIndexChange procedure. I modified my XML file so that I have an
extra attribute in the elements now:

<treenode text="Joe Blow" idEmp="12345">

I did this after looking closely at the "About the TreeView WebControl" at
msdn, but I don't see how you relay this value to the procedure. I guess I
am looking for something like this:

label1.text = Treeview1.GetNodeFromIndex(Treeview1.SelectedNode("idEmp"))

The above line doesn't work of course, but that is what I am thinking...
sorry... I'm a ADO guy and I think that way out of habit! It seems like I
am thinking of this in the wrong way.

The msdn explaination also makes it look like I might have to write XSL to
identify the attribute as a node ("Data Binding with XML and XSL Templates"
section). Is that necessary?

An example would be great!

Schoo
 
J

Jeffrey Tan[MSFT]

Hi Schoo,

Thank you for posting in the community!

Based on my understanding, you use IE treeview server control in your web
form, and databinding all the nodes with xml file. In you xml file, you add
"idemp" cutomized attribute, and want to retrieve "idemp" attribute in
SelectedIndexChanged event.
==============================================
Acutally, "idemp" attribute is not a predefined, so it will not render in
the treeview control.(You can determine this through view html source in
your web page)

So you can not get this done. I suggest you use TreeNode.NodeData property
to store your data. I think I have provided you a sample about how to use
NodeData property. Please refer it there.

==============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Schoo

Jeffrey,

I understand what you are saying about the attribute that I need to use as a
key ("idemp") not rendering. I am using the sample code you provided
without success and I suspect I am missing something. I have been
investigating your suggestion to use the TreeNode.NodeData property and have
so far, not been able to get that to work (I was looking for an example of
this on the internet and could not find one). Maybe a more detailed
explaination of what I am doing is what is needed. Here is what I am doing:

Each employee record has a name and an employee ID number. I am placing
them into an XML file in this format:

<TREENODES>
<treenode text="Joe Blow" idEmp="12345">
</treenode>
......
</TREENODES

I have full control on how the XML file is built so I could also add the
idEmp as its own element inside of the treenode with the name in it, but I
am not seeing that in any examples so let me know if that is a change I need
to make. The HTML portion of the code shows the names in the tree and looks
like this:

<ie:TreeView AutoPostBack="True" id="TreeView1" runat="server" ...>
<ie:TreeNode TreeNodeSrc="XML/employee.xml" text="Employees" ...>
</ie:TreeNode>
</ie:TreeView>

That is working fine, and I DO NOT want to show the ID numbers in the tree
on the screen (however having them in the source would be alright)!!! This
HTML then successfully fires the following procedure:

Private Sub Treeview1_SelectedIndexChange(ByVal sender As System.Object,
ByVal e As Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs)
Dim tn As TreeNode =
Treeview1.GetNodeFromIndex(Treeview1.SelectedNodeIndex)
Response.Write(tn.NodeData.ToString)
End Sub

The problem is that the last line of code in that procedure returns a blank.
In fact, I can run "? tn.NodeData.ToString" in the command panel and I get "
". My question is: What do I have to do to pass that employee ID (idEmp)
from the XML and make it available in the procedure so I can populate
another control on the page?

I am hoping the answer is obvious to you.

Sincerely,

Schoo


"Jeffrey Tan[MSFT]" said:
Hi Schoo,

Thank you for posting in the community!

Based on my understanding, you use IE treeview server control in your web
form, and databinding all the nodes with xml file. In you xml file, you add
"idemp" cutomized attribute, and want to retrieve "idemp" attribute in
SelectedIndexChanged event.
==============================================
Acutally, "idemp" attribute is not a predefined, so it will not render in
the treeview control.(You can determine this through view html source in
your web page)

So you can not get this done. I suggest you use TreeNode.NodeData property
to store your data. I think I have provided you a sample about how to use
NodeData property. Please refer it there.

==============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Schoo,

Thanks for your feedback.

I see your concern, your xml file has one extra "idemp" attribute, you want
to bind it with each treenode.

============================================
Unfortunately, to use Xml databinding for TreeView control, you can not
associate extra attribute with treenode.(Except "text" property)

The 2 workaround I can think of:

1). Inherit TreeView control, then override treenode class, add an extra
"idemp" property for treenode control.(I think it is somewhat inconvinient)
2). In the SelectedIndexChanged event, you can get the new selected node's
id, so you can use some common xml IO operation to read associated "idemp"
from the XML file.

I think the approach 2 is simple and may fit your need.

============================================
If you still have concern, please feel free to tell me.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Schoo

Jeffrey,

Thank you for the information. From your response I understand that there
is no way to attach a key value to the items in the webcontrols.treeview
control. Eventually I will need this feature, but for this project I will
be able to take the item in the 'text' field, dismantle it and use it to
find the ID number by querying the database. Not very efficient (requires
another trip to the database for something that is already in the XML file),
but will get the job done for this project. Eventually I will get a chance
to look at your first option: inheriting the control and adding a property.
I admit that I am not that good with XML yet and so this may take some time.

I find it hard to believe that no one else has ever had to deal with this
issue, but I have not been able to find any examples or dialogue on any
internet help sites on this issue, so it must be that no one has. If you
have any suggestions on how to inherit the control and add the attribute as
a key, please let me know and I will store it until I can get to that. For
now I will work on getting this project completed.

I appreciate all the help you have given me on this.

Sincerely,

Schoo
:)
 
J

Jeffrey Tan[MSFT]

Hi Schoo,

Thanks for your feedback.

I am glad I can help you :)

I will monitor this group, if you have further concern, please feel free to
post, I will hellp you.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Forum statistics

Threads
474,093
Messages
2,570,607
Members
47,227
Latest member
bluerose1

Latest Threads

Top