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

Song Aankhen Khuli Ho lyrics notation

Song : Aankhen Khuli Ho Movie: Mohabbatein Notes used : W=>Western - C D E F G- A- B-/ H=>Hindustani - S R G M P- D- N- ( Here for western, G=G-, A=A-, & B=B- ) ( For hindustani, P=P-, D=D-, & N=N- ) Song I : Aankhen Khuli...Ho Ya.. Ho Bandh W=> A.... C... B..C.. E.. E...... A... A.... H=> D... S... N..S.. G G....... D... D.... Deedaar Un Ka Ho.o.taa Hai.. W=> A...B....A....D.BAG....ADB... H=> D...N...D.....R.NDP...DRN... Kaise Kahoon Main O..Yaaraa W=> B..D.. D....E.... D.....C..C..C... H=> N..R.. R....G... R.....S..S..S..... Ye Pyaar Kaise Hota Hai W=> E...B.....DB...AG...B..AA H=> G...N....RN...DP...N...DD (Tururu ru ru, ru ru rururu ru......) W=> AA...GA...BCE..., B...DB..GA H=> DD...PD...NSG..., N..RN.. PD Song II: Aa.aj He Kisi..par Yaa.ro.on..., Marke De..Khe..gein Hum W=> E....FEDCBABC.D.. D D......., G A B C.... E.......D...D..... H=> G....MGRSNDNS.R. R R......., P D N S.....G........R...R.... Pyaar Ho