Hi,
I have a 2 Level(Parent & Child) Treeview.
and i set Parent Node ExpandMode = TreeNodeExpandMode.ServerSide;
How do we set Checked=true if user has previously selected Child nodes (lets assume i am getting the previous selected values from the Database)
Thank you
I have a 2 Level(Parent & Child) Treeview.
and i set Parent Node ExpandMode = TreeNodeExpandMode.ServerSide;
How do we set Checked=true if user has previously selected Child nodes (lets assume i am getting the previous selected values from the Database)
Thank you
3 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 03 Jan 2014, 06:22 AM
Hi,
I guess you want to check the RadTreeView Child nodes based on the values from the database. Please have a look into the following code snippet.
ASPX:
C#:
Please provide your code if it doesn't help.
Thanks,
Princy.
I guess you want to check the RadTreeView Child nodes based on the values from the database. Please have a look into the following code snippet.
ASPX:
<
telerik:RadTreeView
ID
=
"RadTreeView1"
runat
=
"server"
>
</
telerik:RadTreeView
>
C#:
protected
void
Page_Load(
object
sender, EventArgs e)
{
SqlDataAdapter adapter =
new
SqlDataAdapter(
"SELECT * from Details "
, ConfigurationManager.ConnectionStrings[
"NorthwindConnectionString"
].ConnectionString);
DataTable data =
new
DataTable();
adapter.Fill(data);
RadTreeView1.DataSource = data;
RadTreeNodeBinding binding =
new
RadTreeNodeBinding();
binding.CheckedField =
"status"
;
binding.Checkable =
true
;
RadTreeView1.DataFieldID =
"id"
;
RadTreeView1.DataTextField =
"text"
;
RadTreeView1.DataFieldParentID =
"parentid"
;
RadTreeView1.DataBindings.Add(binding);
RadTreeView1.CheckBoxes =
true
;
RadTreeView1.DataBind();
}
Please provide your code if it doesn't help.
Thanks,
Princy.
0

Venkata
Top achievements
Rank 1
answered on 03 Jan 2014, 03:39 PM
Thanks Princy But your solution doesn't help me
here is my requirement.. User select some parent nodes and some child nodes and save to the database. while Edit we have to show/checked what he was selected previously.
here is my code:
protected void radTree_NodeExpand(object sender, RadTreeNodeEventArgs e)
{
DataTable dtUsers = LoadUsers(Convert.ToInt32(e.Node.Value));
foreach (DataRow row in dtUsers.Rows)
{
RadTreeNode treeUsers = new RadTreeNode(row["UName"].ToString(), row["UID"].ToString());
e.Node.Nodes.Add(treeUsers);
}
}
//while Editing we have to check/selected previous selected Company
private void LoadPreviousSelectedCompanyList()
{
string[] objSelectedCompany = getDataFrom Database();
foreach (string strCompany in objSelectedCompany)
{
RadTreeNode foundNode = radTree.FindNodeByValue(strCompany);
if (foundNode != null)
foundNode.Checked = true;
}
}
But how do we set Previous Selected Userlist(Because until click on Node Expand we are not loading the Userlist)?
here is my requirement.. User select some parent nodes and some child nodes and save to the database. while Edit we have to show/checked what he was selected previously.
here is my code:
<
telerik:RadTreeView
ID
=
"radTree"
Height
=
"250px"
runat
=
"server"
CheckChildNodes
=
"true"
Skin
=
"WebBlue"
CheckBoxes
=
"true"
onnodeexpand
=
"radTree_NodeExpand"
>
</
telerik:RadTreeView
>
private void LoadCompanyList()
{DataTable DT = GetData();
radTree.Nodes.Clear();
RadTreeNode nodeCompany = new RadTreeNode();
foreach (DataRow row in DT.Rows)
{
nodeCompany = new RadTreeNode(row["CName"].ToString(), row["CID"].ToString());
radTree.Nodes.Add(nodeCompany);
nodeCompany.ExpandMode = TreeNodeExpandMode.ServerSide;
}
}protected void radTree_NodeExpand(object sender, RadTreeNodeEventArgs e)
{
DataTable dtUsers = LoadUsers(Convert.ToInt32(e.Node.Value));
foreach (DataRow row in dtUsers.Rows)
{
RadTreeNode treeUsers = new RadTreeNode(row["UName"].ToString(), row["UID"].ToString());
e.Node.Nodes.Add(treeUsers);
}
}
//while Editing we have to check/selected previous selected Company
private void LoadPreviousSelectedCompanyList()
{
string[] objSelectedCompany = getDataFrom Database();
foreach (string strCompany in objSelectedCompany)
{
RadTreeNode foundNode = radTree.FindNodeByValue(strCompany);
if (foundNode != null)
foundNode.Checked = true;
}
}
But how do we set Previous Selected Userlist(Because until click on Node Expand we are not loading the Userlist)?
0
Hi Venkata,
You should set the checked property of the treeUsers node in NodeExpand event to true in case the node should be checked after populating.
Hope this will help you solve the issue.
Regards,
Plamen
Telerik
You should set the checked property of the treeUsers node in NodeExpand event to true in case the node should be checked after populating.
Hope this will help you solve the issue.
Regards,
Plamen
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.