Thursday, October 25, 2012

Treeview with radio button in asp.net

aspx:

<asp:TreeView ID="tvLevel" ExpandDepth="1" PopulateNodesFromClient="true" ShowLines="true"
ShowExpandCollapse="true" runat="server" Width="255px" Height="120px" Style="overflow: auto;
border: 1px solid #999999; border-radius: 4px 4px 4px 4px;"></asp:TreeView>
aspx.cs:

private void ShowLevelTreeview(int ParentID)
{
tvLevel.Nodes.Clear();

ResponseStore<List<ECS.Business.Foundation.Level>> LevelList = objLevelBroker.LevelSelectByParentID(ParentID);
if (LevelList.Object != null){
objParentNodesList = LevelList.Object;

foreach (ECS.Business.Foundation.Level treeNode in objParentNodesList.Where(item => item.ID == item.ParentID)){

TreeNode ParentNode = new TreeNode();ParentNode.Text =
"<input type='radio' name='rbLevel' value ='" + treeNode.ID.ToString() + "' id='rbLevel" + radindex + "'/>" + treeNode.Name;radindex++;

// ParentNode.Text =treeNode.Name.ToString();ParentNode.Value = treeNode.ID.ToString();
tvLevel.Nodes.Add(ParentNode);
RecursiveChild(ParentNode);
}
}
}
private void RecursiveChild(TreeNode ParentNode){

if (objParentNodesList.Count(item => item.ID != item.ParentID && item.ParentID.ToString() == ParentNode.Value) > 0){

foreach (ECS.Business.Foundation.Level chTreeNode in objParentNodesList.Where(item => item.ID != item.ParentID && item.ParentID.ToString() == ParentNode.Value)){

TreeNode childNode = new TreeNode();childNode.Text =
"<input type='radio' name='rbLevel' value ='" + chTreeNode.ID.ToString() + "' id='rbLevel" + radindex + "'/>" + chTreeNode.Name;radindex++;
childNode.Value = chTreeNode.ID.ToString();
ParentNode.ChildNodes.Add(childNode);
RecursiveChild(childNode);
}
}
}

No comments:

Post a Comment