<asp:DropDownList ID="ddclient" runat="server" Width="125px" >
</asp:DropDownList>
<table>
<tr>
<td valign="top" align="left">
<asp:TreeView ID="treeClient" runat="server" Visible="False">
</asp:TreeView>
</td>
<td valign="top" align="left">
<asp:DropDownList ID="DropDownListTree" runat="server" Visible="False">
</asp:DropDownList>
</td>
</tr>
</table>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
If Not Page.IsPostBack Then
PopulateRootLevel()
AddNoteToCombo(treeClient.Nodes, "")
fillOrg4client()
End If
Catch ex As Exception
End Try
End Sub
Private Sub fillOrg4client()
Dim rw As New ListItem
ddclient.Items.Clear()
For Each lis As ListItem In DropDownListTree.Items
Dim sr = Replace(lis.Text, "%o", "")
sr = Replace(sr, "%p", "")
'If sr.Contains(cmbClient.SelectedItem.Text) Then
' If cmbClient.SelectedItem.Text <> sr Then
rw = New ListItem
rw.Text = sr
rw.Value = lis.Value
ddclient.Items.Add(rw)
' End If
'End If
Next
'End If
rw = New ListItem()
rw.Text = "Select"
rw.Value = -1
ddclient.Items.Insert(0, rw)
ddclient.SelectedValue = -1
End Sub
Private Sub treeClient_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles treeClient.TreeNodePopulate
PopulateSubLevel(CInt(e.Node.Value), e.Node)
End Sub
Private Sub AddNoteToCombo(ByVal nc As TreeNodeCollection, ByVal str As String)
For i As Integer = nc.Count - 1 To 0 Step -1
Dim lst As New ListItem
lst.Value = nc(i).Value
str = Replace(str, "Surgere%o", "", 1, 9) 'Remove this to add surge to all
If str = "" Then
lst.Text = nc(i).Text
Else
lst.Text = str + "\" + nc(i).Text
End If
If Not lst.Text.Equals("Surgere%o") Then
DropDownListTree.Items.Add(lst)
End If
If nc(i).ChildNodes.Count > 0 Then
If str = "" Then
AddNoteToCombo(nc(i).ChildNodes, nc(i).Text)
Else
AddNoteToCombo(nc(i).ChildNodes, str + "\" + nc(i).Text)
End If
End If
'If nc(i).ChildNodes.Count = 0 Then
' End If
Next
End Sub
Private Sub PopulateRootLevel()
DropDownListTree.Items.Clear()
Dim stBuilder As New StringBuilder()
stBuilder.Append("select CLIENT_ID,CLIENT_NAME,o_or_p,active_yn,(select count(*) FROM client ")
stBuilder.Append(" WHERE reports_to_id=sc.CLIENT_ID) childnodecount FROM client sc where reports_to_id=0")
Dim selectQry = stBuilder.ToString()
'Dim selectQry = "select CLIENT_ID,CLIENT_NAME,o_or_p,active_yn,(select count(*) FROM client " &
' " WHERE reports_to_id=sc.CLIENT_ID) childnodecount FROM client sc where reports_to_id=0"
'Dim cmm As SqlCommand = New SqlCommand(selectQry)
'Dim result As Object
Dim dtTree = New DataTable
dtTree = DataConnect.GetInstance.GetDt(selectQry)
PopulateNodes(dtTree, treeClient.Nodes, "")
treeClient.ExpandAll()
End Sub
Private Sub PopulateNodes(ByVal dt As DataTable, ByVal nodes As TreeNodeCollection, ByVal st As String)
For Each dr As DataRow In dt.Rows
Dim tn As New TreeNode()
tn.Text = dr("client_name").ToString() ' + "<asp:ImageButton runat='server' ImageUrl='~/Images/plus.gif' onClick='clickPlus()'>"
tn.Value = dr("client_id").ToString()
If dr("o_or_p").ToString().Trim() = "p" Then
tn.Text = tn.Text + "%p"
Else
tn.Text = tn.Text + "%o"
End If
tn.Target = dr("client_name").ToString()
nodes.Add(tn)
'DropDownListTree.Items.Add(st + ">" + tn.Text)
'If node has child nodes, then enable on-demand populating
tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
Next
End Sub
Private Sub PopulateSubLevel(ByVal parentid As Integer, ByVal parentNode As TreeNode)
Dim stBuilder As New StringBuilder()
stBuilder.Append("select CLIENT_ID,CLIENT_NAME,o_or_p,active_yn,(select count(*) FROM client ")
stBuilder.Append(" WHERE reports_to_id=sc.CLIENT_ID) childnodecount FROM client sc where reports_to_id=@parentID")
Dim selectQry = stBuilder.ToString()
'Dim selectQry = "select CLIENT_ID,CLIENT_NAME,o_or_p,active_yn,(select count(*) FROM client " &
' " WHERE reports_to_id=sc.CLIENT_ID) childnodecount FROM client sc where reports_to_id=@parentID"
Dim objCommand = New SqlCommand(selectQry)
objCommand.Parameters.Add("@parentID", SqlDbType.Int).Value = parentid
Dim dt = New DataTable
dt = DataConnect.GetInstance.GetDt(objCommand)
PopulateNodes(dt, parentNode.ChildNodes, "")
End Sub
No comments:
Post a Comment