Tree databinding in vb.net and sql 2005
Private Sub PopulateTree() Dim strSql As String Dim strMenuDesc As String Dim strMenuString As String Dim strMenuType As String Dim dr As SqlClient.SqlDataReader Dim ndParent As TreeNode Dim ndChild As TreeNode trvBalSheetMaster.Nodes.Clear() 'strSql = "select Id,description,parentid from acc_balsheetmaster where id not in (select balsheetinedx_id from Acc_balsheetschedulemappingMaster)order by id" 'dr = NewDataReader(strSql) dr = NewDataReaderByProc("acc_balsheettreebind") While dr.Read If dr.Item("parentid") = 0 Then strMenuDesc = dr.Item("description") ndParent = New TreeNode(strMenuDesc) ndParent.Tag = dr.Item("id") If Convert.ToInt16(dr.Item("id")) = 0 Then ndParent.ImageIndex = dr.Item("id").ToString().Trim() Else ndParent.ImageIndex = Convert.ToInt16(dr.Item("id")) End If trvBalSheetMaster.Nodes.Add(ndParent) Else strMenuDesc = dr.Item("description") ndParent = getNodeByTag(dr.Item("parentid"), trvBalSheetMaster.Nodes) ndChild = ndParent.Nodes.Add(strMenuDesc) ndChild.Tag = dr.Item("id") If Convert.ToInt16(dr.Item("id")) = 0 Then ndChild.ImageIndex = dr.Item("parentid").ToString().Trim() Else ndChild.ImageIndex = Convert.ToInt16(dr.Item("id")) End If End If blnFind = False End While dr.Close() End Sub Private Function getNodeByTag(ByVal pStrTag As String, ByVal pTrNode As TreeNodeCollection) As TreeNode Dim tNode As TreeNode Dim retNode As TreeNode For Each tNode In pTrNode If tNode.Tag = pStrTag Then retNode = tNode blnFind = True ElseIf tNode.Nodes.Count <> 0 And blnFind = False Then retNode = getNodeByTag(pStrTag, tNode.Nodes) End If Next getNodeByTag = retNode End Function
|
No responses found. Be the first to respond and make money from revenue sharing program.
|