set child node width

2 posts, 0 answers
  1. Jayanthy Kapistalam
    Jayanthy Kapistalam avatar
    12 posts
    Member since:
    Oct 2008

    Posted 11 Dec 2008 Link to this post

    I'm populating my tree view nodes using code behind. I'm applying back ground color to the child nodes. Each chidl node is of different size. I want all the child nodes to be of the same size (like a table row). How do I set the width of the node? I tried to set the node width property, but it doesn't work.

    Here is my code. In the following code, child node's text "hello" and "Hi there how are you and how is life" are of two different sizes. I would like to set the node width, so that both the nodes appear to look like they are in a table. I tried the text in table, still didn't work. Any ideas?

    protected void st_NodeExpand(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
            {
                         rdr = ......
                        while (rdr.Read())
                        {

                            RadTreeNode node = new RadTreeNode();
                            if (rdr["Sex"].ToString() == "Male")
                            {
                                node.BackColor = System.Drawing.ColorTranslator.FromHtml("#dfe7fa");
                                node.Text = "<font color='#00685c'><a  href='" + rdr["PortraidID"] + "'>" + "Hello"+"</a></font>";
                            }
                            else
                            {
                                node.Text = "<font color='#00685c'><a  href='" + rdr["PortraidID"] + "'>" + "Hi there how are you and how is life"+"</a></font>";                          
                                node.BackColor = System.Drawing.ColorTranslator.FromHtml("#fdebfb");
                            }
                            node.Value = rdr["PortraidID"].ToString();
                            e.Node.Nodes.Add(node);
                            e.Node.Expanded = true;
                        }

    rdr = new Select("PortraidID,BirthDate,FirstName,LastName,FatherFN,MotherFN,Sex")
                                                    .From("BirthDetails")
                                                    .Where("Month(BirthDate)").IsEqualTo(Convert.ToInt32(month))
                                                    .And("Year(BirthDate)").IsEqualTo(Convert.ToInt32(my[1]))
                                                    .OrderAsc("BirthDate")
                                                    .ExecuteReader();
                        while (rdr.Read())
                        {

                            RadTreeNode node = new RadTreeNode();



                            if (rdr["Sex"].ToString() == "Male")
                            {
                                node.BackColor = System.Drawing.ColorTranslator.FromHtml("#dfe7fa");
                                node.Text = "<font color='#00685c'><a  href='BabyDetail.aspx?id=" + rdr["PortraidID"] + "'>" + Convert.ToDateTime(rdr["BirthDate"].ToString()).ToShortDateString() + " " + rdr["FirstName"] + " " + rdr["LastName"] + "- Son of " + rdr["FatherFN"] + " & " + rdr["MotherFN"] + "</a></font>";
                            }
                            else
                            {
                                node.Text = "<font color='#00685c'><a  href='BabyDetail.aspx?id=" + rdr["PortraidID"] + "'>" + Convert.ToDateTime(rdr["BirthDate"].ToString()).ToShortDateString() + " " + rdr["FirstName"] + " " + rdr["LastName"] + "- Daughter of " + rdr["FatherFN"] + " & " + rdr["MotherFN"] + "</a></font>";
                               
                                node.BackColor = System.Drawing.ColorTranslator.FromHtml("#fdebfb");
                            }
                            node.Value = rdr["PortraidID"].ToString();

                            e.Node.Nodes.Add(node);
                            e.Node.Expanded = true;
                        }
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 11 Dec 2008 Link to this post

    Hi Jayanthy Kapistalam,

    By default the nodes are inline elements which means they don't have width. You can try adding this CSS rule in your page to make the nodes inline-block elements:

    <style type="text/css">
    div.RadTreeView span.rtIn
    {
       display:inline-block;
    }
    </style>

    Then the setting the Width property should work.

    Regards,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top