Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL Server
I have created a treeview, which is binding categories and subcategories from database.
 
I want to display an icon (image) on left side of the treeview. For example, in treeview I have categories such as amana tool as a parent node and the router bits as child node of amana tool. So, in database I have icon of amana tool as well as icon of router bits. Now, I am able to show categories (amana tool) only in treeview. But, I need that left side should show the icon of the related categories and then categories name(amana tool).
 

Note: The icon should bind from database but it should not be static icon because I need to show more than 100 categories and the icon existing in database.
 
Please help me out.
Posted 11-Jul-13 2:10am
Edited 11-Jul-13 3:30am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
You have to define a tree view item as a seperate class. In that class define propertys like header, url and image source. see below code for more understand.
Define a tree view item as class name MenuItem.
Code:
 
MenuItem Class:
public class MenuItem
    {
        public string Header { get; set; }
        public string Url { get; set; }
        public BitmapImage ImageSource { get; set; }
        public List<menuitem> SubMenuItems { get; set; }
    }
 
List <menuitem> MenuItems = new List<menuitem>();
MenuItems.Add(
                    new MenuItem()
                    {
                        Header = "Display Name",
                        Url = "NavigationUrl",
                        ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("ur image url from database", UriKind.RelativeOrAbsolute)),
                                            });
//Bind menitems list to ur treeview 
tvLeftMenu.ItemsSource = MenuItems;
Thanks
Anil
  Permalink  
v2
Comments
christhuxavier at 11-Jul-13 9:09am
   
hi bitmapimage is throwing error in c# asp.net.
Anilkumar2vvv at 11-Jul-13 9:35am
   
please post the error ...
Anilkumar2vvv at 11-Jul-13 9:57am
   
use this reference using System.Windows.Media.Imaging;

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



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 11 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100