This is a migrated thread and some comments may be shown as answers.

set child node width

1 Answer 117 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jayanthy Kapistalam
Top achievements
Rank 1
Jayanthy Kapistalam asked on 11 Dec 2008, 02:44 PM
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;
                    }

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 11 Dec 2008, 05:35 PM
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.
Tags
TreeView
Asked by
Jayanthy Kapistalam
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or