Setting select nodes as checked server side

4 posts, 1 answers
  1. Bruce St.Clair
    Bruce St.Clair avatar
    27 posts
    Member since:
    Jan 2008

    Posted 17 Sep 2008 Link to this post

    When I databind serverside I want to set certain nodes as checked.  I poured through the forums and help files but cant find anything close to what I am doing.

    Code Snippet:

    try

    {

    DataSet dsp = new DataSet();

    DB.m_da.SetRead("SELECT 'All Providers' AS [Name], '0' AS [ID], null as tree union SELECT [FName] + ' ' + [LName] AS [Name], [ID],0 as [Tree] FROM Provider WHERE [Inactive] = 0 ORDER BY 1", 1);

    DB.m_da.Run(ref dsp);

    RadTreeView1.DataSource = dsp;

    RadTreeView1.DataFieldID =

    "ID";

    RadTreeView1.DataValueField =

    "ID";

    RadTreeView1.DataTextField =

    "Name";

    RadTreeView1.DataFieldParentID =

    "Tree";

    RadTreeView1.DataBind();

    DataSet ds = new DataSet();

    DB.m_da.SetRead("Select VID from AppointmentUserSetting where onoff = 1", 1);

    DB.m_da.Run(ref ds);

    foreach (DataRow row in ds.Tables[0].Rows)

    {

    // This is where I want to set the node to checked

    // node.checked = true;

    }

    RadTreeView1.ExpandAllNodes();

    RadTreeView1.MultipleSelect =

    true;

    RadTreeView1.CheckBoxes =

    true;

    Label1.Text =

    "";

     

     

    }

  2. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 19 Sep 2008 Link to this post

    Hi Bruce St.Clair,

    You should use the NodeDataBound event to set the Checked property of the nodes created during databinding.

    Regards,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Bruce St.Clair
    Bruce St.Clair avatar
    27 posts
    Member since:
    Jan 2008

    Posted 19 Sep 2008 Link to this post

    Well I came up with a different approach and thought I should share it incase anybody else runs into the same problem.  My data is for the tree comes from 2 completely differnet areas of my database.  1 area is to fill the tree and the checked box selection come from a user preferences ara.  So below you will find my approach to fit my needs with comments.  Hope this help anybody else they may need this approach.

    Code snippet.

    RadTreeView1.Nodes.Clear();

    //Set our crud layer

    DataAccess.

    DA dt = new DA("Connection string");

    DB.m_da = dt;

    try

    {

    //Get all the data to fill the tree without the check boxes filled

    DataSet dsp = new DataSet();

    DB.m_da.SetRead(

    "SELECT 'All Providers' AS [Name], '0' AS [ID], null as tree union SELECT [FName] + ' ' + [LName] AS [Name], [ID],0 as [Tree] FROM Provider WHERE [Inactive] = 0 ORDER BY 1", 1);

    DB.m_da.Run(

    ref dsp);

     

    //Databind the tree to show all doctors

    RadTreeView1.DataSource = dsp;

    RadTreeView1.DataFieldID =

    "ID";

    RadTreeView1.DataValueField =

    "ID";

    RadTreeView1.DataTextField =

    "Name";

    RadTreeView1.DataFieldParentID =

    "Tree";

    RadTreeView1.DataBind();

    //Now get the users previous selections of what doctor they have selected to view in the calendar

    DataSet ds = new DataSet();

    DB.m_da.SetRead(

    "Select VID from AppointmentUserSetting where onoff = 1 and UID = 1 and IDType = 'D'", 1);

    DB.m_da.Run(

    ref ds);

    // Now apply the check boxes to match what the user selection are if 0 then select root parent

    // If not root then fill in the correct check boxes

    foreach (DataRow row in ds.Tables[0].Rows)

    {

    if (row.ItemArray.GetValue(0).ToString() == "0")

    {

    RadTreeNode rtn =

    this.RadTreeView1.FindNodeByValue(row.ItemArray.GetValue(0).ToString());

    rtn.Checked =

    true;

    break;

    }

    else

    {

    RadTreeNode rtn =

    this.RadTreeView1.FindNodeByValue(row.ItemArray.GetValue(0).ToString());

    rtn.Checked =

    true;

    }

    }

    //now set the tree to my liking

    RadTreeView1.ExpandAllNodes();

    RadTreeView1.MultipleSelect =

    true;

    RadTreeView1.CheckBoxes =

    true;

    }

  4. Bruce St.Clair
    Bruce St.Clair avatar
    27 posts
    Member since:
    Jan 2008

    Posted 19 Sep 2008 Link to this post

    Well I came up with a different approach and thought I should share it incase anybody else runs into the same problem.  My data is for the tree comes from 2 completely differnet areas of my database.  1 area is to fill the tree and the checked box selection come from a user preferences ara.  So below you will find my approach to fit my needs with comments.  Hope this help anybody else they may need this approach.

    Code snippet.

    RadTreeView1.Nodes.Clear();

    //Set our crud layer

    DataAccess.

    DA dt = new DA("Connection string");

    DB.m_da = dt;

    try

    {

    //Get all the data to fill the tree without the check boxes filled

    DataSet dsp = new DataSet();

    DB.m_da.SetRead(

    "SELECT 'All Providers' AS [Name], '0' AS [ID], null as tree union SELECT [FName] + ' ' + [LName] AS [Name], [ID],0 as [Tree] FROM Provider WHERE [Inactive] = 0 ORDER BY 1", 1);

    DB.m_da.Run(

    ref dsp);

     

    //Databind the tree to show all doctors

    RadTreeView1.DataSource = dsp;

    RadTreeView1.DataFieldID =

    "ID";

    RadTreeView1.DataValueField =

    "ID";

    RadTreeView1.DataTextField =

    "Name";

    RadTreeView1.DataFieldParentID =

    "Tree";

    RadTreeView1.DataBind();

    //Now get the users previous selections of what doctor they have selected to view in the calendar

    DataSet ds = new DataSet();

    DB.m_da.SetRead(

    "Select VID from AppointmentUserSetting where onoff = 1 and UID = 1 and IDType = 'D'", 1);

    DB.m_da.Run(

    ref ds);

    // Now apply the check boxes to match what the user selection are if 0 then select root parent

    // If not root then fill in the correct check boxes

    foreach (DataRow row in ds.Tables[0].Rows)

    {

    if (row.ItemArray.GetValue(0).ToString() == "0")

    {

    RadTreeNode rtn =

    this.RadTreeView1.FindNodeByValue(row.ItemArray.GetValue(0).ToString());

    rtn.Checked =

    true;

    break;

    }

    else

    {

    RadTreeNode rtn =

    this.RadTreeView1.FindNodeByValue(row.ItemArray.GetValue(0).ToString());

    rtn.Checked =

    true;

    }

    }

    //now set the tree to my liking

    RadTreeView1.ExpandAllNodes();

    RadTreeView1.MultipleSelect =

    true;

    RadTreeView1.CheckBoxes =

    true;

    }

Back to Top