Skip to main content

Show parent child node value at runtime and populate treeview in asp.net

Show parent child node value at runtime and populate treeview in asp.net.

This program is use to populate treeview at runtime using asp.net. you can try this code.

 Imports System.Data  
 Imports System.Configuration  
 Imports System.Web  
 Imports System.Web.Security  
 Imports System.Web.UI  
 Imports System.Web.UI.WebControls  
 Imports System.Web.UI.WebControls.WebParts  
 Imports System.Web.UI.HtmlControls  
 Imports System.Data.SqlClient  
 Imports System.Web.UI.WebControls.TreeNode  
 Partial Class Bibliography  
 Inherits System.Web.UI.Page  
 Dim clscmn1 As New clsCommon  
 Dim cn As New clsConnection  
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
 If Not IsPostBack Then  
 PopulateRootLevel()  
 Else  
 Exit Sub  
 End If  
 End Sub  
 Private Sub PopulateRootLevel()  
 Dim dt1 As New DataTable()  
 Dim objCommand As New SqlCommand("select PRODUCT_CATEGORY_CD,PRODUCT_CATEGORY,(select count(*) FROM PRODUCT_CATEGORY " _  
 & "WHERE PARENT_CATEGORY_CD=sc.PRODUCT_CATEGORY_CD) as childnodecount FROM PRODUCT_CATEGORY sc where PARENT_CATEGORY_CD IS NULL", _  
 cn.openDb)  
 Dim da As New SqlDataAdapter(objCommand)  
 da.Fill(dt1)  
 PopulateNodes(dt1, TreeView1.Nodes)  
 End Sub  
 Private Sub PopulateSubLevel(ByVal PARENT_CATEGORY_CD As String, ByVal parentNode As TreeNode)  
 cn.closeDb()  
 Dim objCommand As New SqlCommand("select PRODUCT_CATEGORY_CD,PRODUCT_CATEGORY,(select count(*) FROM PRODUCT_CATEGORY " _  
 & "WHERE PARENT_CATEGORY_CD=sc.PRODUCT_CATEGORY_CD) as childnodecount FROM PRODUCT_CATEGORY sc where PARENT_CATEGORY_CD=@PARENT_CATEGORY_CD", _  
 cn.openDb)  
 objCommand.Parameters.Add("@PARENT_CATEGORY_CD", SqlDbType.Char).Value = PARENT_CATEGORY_CD  
 Dim da As New SqlDataAdapter(objCommand)  
 Dim dt As New DataTable()  
 da.Fill(dt)  
 PopulateNodes(dt, parentNode.ChildNodes)  
 End Sub  
 Private Sub PopulateNodes(ByVal dt As DataTable, ByVal nodes As TreeNodeCollection)  
 'For Each dr As DataRow In dt.Rows  
 ' Dim tn As New TreeNode()  
 ' tn.Text = dr("PRODUCT_CATEGORY").ToString().Trim  
 ' tn.Value = dr("PRODUCT_CATEGORY_CD").ToString().Trim  
 ' nodes.Add(tn)  
 ' 'If node has child nodes, then enable on-demand populating  
 ' tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)  
 'Next  
 For Each dr As DataRow In dt.Rows  
 Dim tn As New TreeNode()  
 tn.Text = dr("PRODUCT_CATEGORY").ToString().Trim  
 tn.Value = dr("PRODUCT_CATEGORY_CD").ToString().Trim  
 Dim NoofChild As Integer = Convert.ToInt32(dr("childnodecount").ToString().Trim)  
 If NoofChild <> 0 Then  
 tn.PopulateOnDemand = True  
 ' tn.SelectAction = TreeNodeSelectAction.None  
 Else  
 tn.PopulateOnDemand = False  
 'If dr("TotalDoc").ToString().Equals("0") = False Then  
 ' tn.NavigateUrl = "~/CategoryWiseProductList.aspx?ID=" + dr("CategoryID").ToString()  
 ' tn.Text = tn.Text + " (" + dr("TotalProduct").ToString() & ")"  
 'Else  
 ' tn.NavigateUrl = "javascript:alert('Product is not Available Under this Category.')"  
 'End If  
 End If  
 nodes.Add(tn)  
 Next  
 End Sub  
 Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate  
 PopulateSubLevel(e.Node.Value, e.Node)  
 Session("Productbib") = e.Node.Value  
 End Sub  
 Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged  
 Session("Productbib") = TreeView1.SelectedValue  
 If (Session("Productbib") <> "") Then  
 Response.Redirect("abc.aspx")  
 End If  
 End Sub  

Popular posts from this blog

Resolved : Power BI Report connection error during execution

Getting Below Power BI Report connection error during execution . Error: Something went wrong Unable to connect to the data source undefined. Please try again later or contact support. If you contact support, please provide these details. Underlying error code: -2147467259 Table: Business Sector. Underlying error message: AnalysisServices: A connection cannot be made. Ensure that the server is running. DM_ErrorDetailNameCode_UnderlyingHResult: -2147467259 Microsoft.Data.Mashup.ValueError.DataSourceKind: AnalysisServices Microsoft.Data.Mashup.ValueError.DataSourcePath: 10.10.10.60;T_CustomerMaster_ST Microsoft.Data.Mashup.ValueError.Reason: DataSource.Error Cluster URI: WABI-WEST-EUROPE-redirect.analysis.windows.net Activity ID: c72c4f12-8c27-475f-b576-a539dd81826a Request ID: dfb54166-c78f-4b40-779f-e8922a6687ad Time: 2019-09-26 10:03:29Z Solution: We found report connection not able to connect to SQL Analysis service so tried below option. Re

Song- Khamoshiyan Piano keyboard Chord,Notation and songs Lyrics

All songs notation and chords at one place

Song : O Saathi Re Film : Mukhathar Ka Sikkandhar Uses : C D D# E G A Note : The numbers at the end of the lines indicate line numbers. Pallavi: O saathi re, tere binaa bhi kya jina, tere binaa bhi kya jina A- C D D#....,D D C DD E...C..CA-...,D D C DD E...CC.......1 Play line 1 again phulon men khaliyon men sapnom ki galiyon men GGG...GAGE.. GGG G A G E.................................................2 tere bina kuchh kahin naa E A G E D C D D#.......................................................................3 tere binaa bhi kya jina, tere binaa bhi kya jina D D C DD E....C..CA-..., D D C DDE....CC.............................4 Charanam: har dhadkan men, pyaas hai teri, sanson men teri khushboo hai CCC C D C A-, CCC C D C A-, DDD DED CD EE.. CCCC......................5 is dharthi se, us ambar tak, meri nazar men tu hi tu hai CCC C D C A-, CCC C D C A-, DDD DED CD EE.. CCCC......................6 pyaar yeh tute naa GGG... GAG D#......E.........................