Visual Studio .NET - treeview checkbox css - Asked By Alek Tolstoi on 13-Aug-08 08:47 AM

hi all,


i have an aspx.net treeview user control. i need to add different style to a checkboxes that are selected and not selected, as well as, change the text to different style.


how can i do that? the tree gets populated on the server side and not bound to data source.

Can I use CSS and set each treenode to specific style??? can someone show me how this can be done?

Thanks

reply - Binny ch replied to Alek Tolstoi on 13-Aug-08 02:15 PM

hi,

I think it not possible to set each treenode to specific style..

Well u find the solution please post it to me, if you can friend

Bye..

treenodestyle - Partha Mandayam replied to Alek Tolstoi on 13-Aug-08 05:30 PM

You can manipulate the treenodestyle property. See this link.

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/navigation/treeview.aspx

Try this - ram kumar replied to Alek Tolstoi on 14-Aug-08 01:24 AM

Hi,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link rel="stylesheet" href="SimpleTreeView.css" type="text/css" />
    <link runat="server" rel="stylesheet" href="~/CSS/Import.css" type="text/css" id="AdaptersInvariantImportCSS" />
<!--[if lt IE 7]>
    <link runat="server" rel="stylesheet" href="~/CSS/BrowserSpecific/IEMenu6.css" type="text/css" id="IEMenu6CSS" />
<![endif]-->
<!--[if gt IE 6]>
    <link runat="server" rel="stylesheet" href="~/CSS/BrowserSpecific/IEMenu7.css" type="text/css" id="IEMenu7CSS" />
<![endif]-->
</head>
<body>
    <form id="form1" runat="server">
        <asp:TreeView ID="EntertainmentTreeView" runat="server"
          OnSelectedNodeChanged="OnClick"
          OnAdaptedSelectedNodeChanged="OnClick"
          OnTreeNodeCheckChanged="OnCheckChanged"
          OnAdaptedTreeNodeCheckChanged="OnCheckChanged"
          CssSelectorClass="SimpleEntertainmentTreeView"
          ExpandDepth="0"
          ShowCheckBoxes="Leaf">
            <Nodes>
                <asp:TreeNode Text="Music" SelectAction="Expand">
                    <asp:TreeNode Text="Classical" />
                    <asp:TreeNode Text="Rock" SelectAction="Expand">
                        <asp:TreeNode Text="Electric" />
                        <asp:TreeNode Text="Acoustical" />
                    </asp:TreeNode>
                    <asp:TreeNode Text="Jazz" />
                </asp:TreeNode>
                <asp:TreeNode Text="Movies" SelectAction="Expand">
                    <asp:TreeNode Text="Action" />
                    <asp:TreeNode Text="Drama" />
                    <asp:TreeNode Text="Musical" />
                </asp:TreeNode>
            </Nodes>
        </asp:TreeView>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
       
        <div id="EntertainmentMessage">
            <asp:Label id="MessageLabel" runat="server" />
        </div>
    </form>
</body>
</html> 
    public void OnClick(Object sender, EventArgs e)
    {
        GiveFeedback();
    }

    public void OnCheckChanged(Object sender, TreeNodeEventArgs e)
    {
        GiveFeedback();
    }
   
    public void GiveFeedback()
    {
        MessageLabel.Text = "";
        if (EntertainmentTreeView.SelectedNode != null)
        {
            MessageLabel.Text += "You selected " + EntertainmentTreeView.SelectedNode.Text + ".";
        }
       
        if (EntertainmentTreeView.CheckedNodes.Count > 0)
        {
            MessageLabel.Text += "&lt;br /><br />The checked values are:<ul>";
            foreach (TreeNode item in EntertainmentTreeView.CheckedNodes)
            {
                MessageLabel.Text += "&lt;li>";
                MessageLabel.Text += item.Text;
                MessageLabel.Text += "&lt;/li>";
            }
            MessageLabel.Text += "&lt;/ul>";
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        GiveFeedback();
    }

Link... - Atul Shinde replied to Alek Tolstoi on 14-Aug-08 03:16 AM
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/navigation/treeview.aspx
CSS friendly control adapter - Hemant Singh replied to ram kumar on 19-Aug-09 07:42 AM
Hi Ravi
wiil u Please send me a working code for this page as i am trying to implement this code but its not working
my id is:- rajbpl100@gmail.com
thanks & Regards
hemant