i wrote this proggram..
VB.NET Code
Data Base Shema :
ParameterID <int><PK>
ParentID <AllowNULL><int>
ParameterName<[n]char>
...........................
Return Database PK Of SelectedItems
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> |
<%@ Register assembly="RadTreeView.Net2" namespace="Telerik.WebControls" tagprefix="rad" %> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head runat="server"> |
<title>Untitled Page</title> |
</head> |
<body dir="rtl"> |
<form id="form1" runat="server"> |
<div> |
<rad:RadTreeView ID="RadTreeView1" runat="server" |
> |
</rad:RadTreeView> |
</div> |
<asp:Button ID="Button1" runat="server" Text="Button" /> |
</form> |
</body> |
</html> |
Imports Telerik.WebControls |
Imports System.Data.OleDb |
Imports System.Data |
Partial Class _Default |
Inherits System.Web.UI.Page |
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load |
If Not IsPostBack Then |
RadTreeView1.DataFieldID = "ParameterID" |
RadTreeView1.DataValueField = "ParameterID" |
RadTreeView1.DataTextField = "ParameterName" |
RadTreeView1.DataFieldParentID = "ParentID" |
RadTreeView1.DataSource = GetDataSource() |
RadTreeView1.DataBind() |
BindingTree(RadTreeView1.Nodes) |
End If |
End Sub |
Private Function GetDataSource() As DataTable |
Dim Con As New OleDbConnection("MyConnectionString") |
Dim Cmd As New OleDbCommand |
Dim Adp As New OleDbDataAdapter(Cmd) |
Dim Dataset As New DataSet |
Cmd.Connection = Con |
Con.Open() |
Cmd.CommandText = "SELECT * FROM [TBL]" |
Adp.Fill(Dataset) |
Con.Close() |
Return Dataset.Tables(0) |
End Function |
Private Sub BindingTree(ByVal MyNode As RadTreeNodeCollection) |
For index As Integer = 0 To MyNode.Count - 1 |
If MyNode(index).Nodes.Count > 0 Then |
BindingTree(MyNode(index).Nodes) |
Else |
Dim mylit As New Literal |
mylit.Text = "<input type=""radio"" value=""" & MyNode(index).Value & """ name=""" & GetMainParentID(MyNode(index)).ToString & """ />" & MyNode(index).Text |
MyNode(index).Controls.Clear() |
MyNode(index).Controls.Add(mylit) |
End If |
Next |
End Sub |
Private Function GetStep(ByVal MyNode As RadTreeNode) As Int32 |
If Not MyNode.Parent Is Nothing Then |
Return GetStep(MyNode.Parent) + 1 |
Else |
Return 0 |
End If |
End Function |
Private Function GetMainParentID(ByVal MyNode As RadTreeNode) As Int32 |
Dim ChildStep As Int32 = GetStep(MyNode) |
Dim MainParentNode As RadTreeNode |
MainParentNode = MyNode |
For index As Integer = 1 To ChildStep |
MainParentNode = MainParentNode.Parent |
Next |
Return MainParentNode.Value |
End Function |
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click |
|
Dim Hshtbl As New Hashtable |
Session("MyHsh") = Hshtbl |
ExtractData(RadTreeView1.Nodes) |
Hshtbl = Session("MyHsh") |
For Each TempObj As Object In Hshtbl.Values |
Response.Write(TempObj.ToString + "<BR>") |
Next |
End Sub |
Private Sub ExtractData(ByVal MyNode As RadTreeNodeCollection) |
For index As Integer = 0 To MyNode.Count - 1 |
If MyNode(index).Nodes.Count > 0 Then |
ExtractData(MyNode(index).Nodes) |
Else |
If Not Request.Form(GetMainParentID(MyNode(index)).ToString) = "" Then |
CType(Session("MyHsh"), Hashtable).Item(GetMainParentID(MyNode(index)).ToString) = Request.Form(GetMainParentID(MyNode(index)).ToString) |
Exit For |
End If |
End If |
Next |
End Sub |
End Class |
ParameterID <int><PK>
ParentID <AllowNULL><int>
ParameterName<[n]char>
...........................
Return Database PK Of SelectedItems