Welcome Guest Search | Active Topics | Sign In | Register

TreeView - Handling ItemClick Options
Jeff_M
Posted: Saturday, December 29, 2007 4:24:29 PM
Rank: Newbie
Groups: Member

Joined: 12/28/2007
Posts: 5
I am using the TreeView control for navigation for download files. The files are contained in a SQLServer DB. Some of the tree nodes will initiate a download and others are just for navigation to a specific download file so the property RaisesServerEvent = True is set only on nodes that can trigger a download. I have populated the ItemID with a ID that will be used in a SQL statement to select the download file.

I am using a vb code behind file, but can't seem to figure out how to call the node itemclick event on the aspx page and what vb code to use to handle the click event. I don't need help with the SQL, just a simple example of what I use in the aspx page and the vb code to handle the node itemclick event to do something like change the text of a label would get me going.

Probably pretty simple stuff, but I am pretty green on web based programming. I am using MS Expression Web as the development environment.

Thanks
eo_support
Posted: Saturday, December 29, 2007 5:13:29 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi,

The easiest way for you is to set RaisesServerEvent to true on the TreeView object. This way all nodes, except for those with NavigateUrl set, will trigger server side ItemClick event, that should work exactly for your purpose.

If you still have problem get ItemClick event triggered, try it with a blank form. Usually the code the designer genearated for you would work just fine. If you use Visual Studio, just double click the TreeView control on the design surface should create an empty ItemClick handler for you because ItemClick is TreeView's default event.

Thanks

Jeff_M
Posted: Saturday, December 29, 2007 6:38:56 PM
Rank: Newbie
Groups: Member

Joined: 12/28/2007
Posts: 5
OK, I am not using VS but Expresseion Web, but I think I have figured out the RaisesServerEvent. What was confusing was that if for example, I create a asp button on a aspx page I have to use something like OnClick="btnID". Since the download files are actually in a DB, then I won't be using a url to get the file, but rather SQL, which I know how to do. The node itemid is a column in my DB so by using it in a SELECT stmt I can get the file for the clicked node.

Now what is the vb to get the itemid for the node that is clicked and show that id as label text for a lable on the page?

Thanks
eo_support
Posted: Saturday, December 29, 2007 8:06:52 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi,

That's very easy. The second parameter of ItemClick event should give you everything you need, for example:

Code: Visual Basic.NET
Protected Sub TreeView1_ItemClick(
    ByVal sender as Object, ByVal e as EO.Web.NavigationItemEventArgs)

    'Display the ItemID of the clicked node
    Label1.Text = e.TreeNode.ItemID

End Sub


Thanks
Jeff_M
Posted: Sunday, December 30, 2007 6:11:27 AM
Rank: Newbie
Groups: Member

Joined: 12/28/2007
Posts: 5
Ok it must be something simple but so far no joy. When I click a tree node the label text doesn't change.

Here is what I have on the aspx page for the tree and the label:

<eo:TreeView ID="TreeView1" runat="server" ControlSkinID="None" Height="400px" Width="230px" RaisesServerEvent="True">
<LookNodes>
<eo:TreeNode ExpandedImageUrl="00030302" ItemID="_Default" SelectedStyle-CssText="background-color:#316ac5;border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:White;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;" NormalStyle-CssText="PADDING-RIGHT: 1px; PADDING-LEFT: 1px; PADDING-BOTTOM: 1px; COLOR: black; BORDER-TOP-STYLE: none; PADDING-TOP: 1px; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: transparent; BORDER-BOTTOM-STYLE: none" DisabledStyle-CssText="background-color:transparent;border-bottom-style:none;border-left-style:none;border-right-style:none;border-top-style:none;color:Gray;padding-bottom:1px;padding-left:1px;padding-right:1px;padding-top:1px;" CollapsedImageUrl="00030301" ImageUrl="00030301">
</eo:TreeNode>
</LookNodes>
<TopGroup Style-CssText="border-bottom-color:#999999;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#999999;border-left-style:solid;border-left-width:1px;border-right-color:#999999;border-right-style:solid;border-right-width:1px;border-top-color:#999999;border-top-style:solid;border-top-width:1px;color:black;cursor:hand;font-family:Tahoma;font-size:8pt;padding-bottom:2px;padding-left:2px;padding-right:2px;padding-top:2px;" RaisesServerEvent="True">
<Nodes>

<eo:TreeNode ItemID="1" Text="Drawings" CustomItemID="" RaisesServerEvent="True">

<SubGroup><Nodes>
<eo:TreeNode ItemID="1.1" Text="90 Minute Rated Details" CustomItemID="" RaisesServerEvent="True">

<SubGroup><Nodes>
<eo:TreeNode ItemID="1.1.1" Text="2 Inch Trim" CustomItemID="" RaisesServerEvent="True">

<SubGroup><Nodes>
<eo:TreeNode ItemID="1.1.1.1" Text="DWG Files" CustomItemID="" RaisesServerEvent="True">
</eo:TreeNode>
</Nodes>

</SubGroup>
</eo:TreeNode>
<eo:TreeNode ItemID="1.1.2" Text="Flush Trim" CustomItemID="1.1.2" RaisesServerEvent="True">

<SubGroup><Nodes>
<eo:TreeNode ItemID="1.1.2.1" Text="DWG Files" CustomItemID="" RaisesServerEvent="True">
</eo:TreeNode>
</Nodes>

</SubGroup>
</eo:TreeNode>
<eo:TreeNode ItemID="1.1.3" Text="Reveal Trim" CustomItemID="" RaisesServerEvent="True">

<SubGroup><Nodes>
<eo:TreeNode ItemID="1.1.3.1" Text="DWG Files" CustomItemID="" RaisesServerEvent="True">
</eo:TreeNode>
</Nodes>

</SubGroup>
</eo:TreeNode>
</Nodes>

</SubGroup>
</eo:TreeNode>
</Nodes>

</SubGroup>
</eo:TreeNode>
</Nodes>

</TopGroup>
</eo:TreeView>
<asp:Label runat="server" Text="TreeNodeID" id="Label1"></asp:Label>

Here is the vb code:
Namespace EO.Web.TreeView1.Programming
Partial Class DownloadTree
Inherits System.Web.UI.UserControl

Protected Sub TreeView1_ItemClick(
ByVal sender as Object, ByVal e as EO.Web.NavigationItemEventArgs)

'Display the ItemID of the clicked node
Label1.Text = e.TreeNode.ItemID

End Sub


End Class
End Namespace

Thanks
eo_support
Posted: Sunday, December 30, 2007 6:21:41 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi,

You need to add OnItemClick to hookup the TreeView and the item click handler, just like what you have discovered for a standard ASP.NET button:

Code: HTML/ASPX
<eo:TreeView OnItemClick="TreeView1_ItemClick" ....>
.....
</eo:TreeView>


Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.