bsarahim
asked on
categories and subcategories display in the dropdown/gridview (part 2)
https://www.experts-exchange.com/questions/27626226/categories-and-subcategories-display-in-the-dropdown-gridview.html
Request you to answer the pending portion
Request you to answer the pending portion
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
any of the item it is giving a error..
ASKER
waiting for you reply.. thanks
when the SelectedIndexChanged is triggered, what are the values in the Listbox1?
the listbox1 should contain items like the following:
1->2->6
2->5->8
3->6
in the values in the listbox are not in this format, none of the code will work.
1->2->6
2->5->8
3->6
in the values in the listbox are not in this format, none of the code will work.
ASKER
so instead of list we need dictionary to map category id to name.
can u post the full code?, i'll make the change on that
can u post the full code?, i'll make the change on that
ASKER
Here is the full code.. thanks
Private Sub list_SelectedIndexChanged( ByVal sender As Object, ByVal e As System.EventArgs) Handles listBox1.SelectedIndexChan ged
Dim curItem As String = Listbox1.SelectedItem.Valu e
Dim list As New List(Of Integer)()
Dim tokens = curItem.Split(New String() {"->"}, StringSplitOptions.RemoveE mptyEntrie s)
' Response.Write(tokens.ToSt ring)
'Response.End()
For Each item In tokens
list.Add(Integer.Parse(ite m))
Next
If list.Count > 1 Then
Dim parentCatId As Integer = list(list.Count - 2)
Response.Write(parentCatId )
Else
End If
End Sub
-------------------------- ---------- -
page_onload
If Not (Page.IsPostBack) Then
Dim sqlConn As New SqlConnection
Dim strConn As String
Dim cmd As New SqlClient.SqlCommand
strConn = System.Configuration.Confi gurationMa nager.Conn ectionStri ngs("JC"). Connection String
sqlConn = New SqlConnection(strConn)
'Dim reader1, reader As SqlDataReader
cmd.Connection = sqlConn
sqlConn.Open()
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT [Id] ,[Name] ,[ParentCategoryId] FROM [nopCommerce].[dbo].[Categ ory]", sqlConn)
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet, "Ordersvariant")
Dim dt As DataTable = dataSet.Tables(0)
Dim parentId As Integer = 0
' Dim list As New List(Of String)()
Dim rows = dt.Rows.Cast(Of DataRow)()
Dim item As DataRow
For Each item In rows
parentId = CInt(item("parentcategoryi d"))
Dim name As String = item("Name").ToString()
While parentId > 0
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid "))
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
Listbox1.Items.Add(name)
Next
End If
Private Sub list_SelectedIndexChanged(
Dim curItem As String = Listbox1.SelectedItem.Valu
Dim list As New List(Of Integer)()
Dim tokens = curItem.Split(New String() {"->"}, StringSplitOptions.RemoveE
' Response.Write(tokens.ToSt
'Response.End()
For Each item In tokens
list.Add(Integer.Parse(ite
Next
If list.Count > 1 Then
Dim parentCatId As Integer = list(list.Count - 2)
Response.Write(parentCatId
Else
End If
End Sub
--------------------------
page_onload
If Not (Page.IsPostBack) Then
Dim sqlConn As New SqlConnection
Dim strConn As String
Dim cmd As New SqlClient.SqlCommand
strConn = System.Configuration.Confi
sqlConn = New SqlConnection(strConn)
'Dim reader1, reader As SqlDataReader
cmd.Connection = sqlConn
sqlConn.Open()
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT [Id] ,[Name] ,[ParentCategoryId] FROM [nopCommerce].[dbo].[Categ
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet, "Ordersvariant")
Dim dt As DataTable = dataSet.Tables(0)
Dim parentId As Integer = 0
' Dim list As New List(Of String)()
Dim rows = dt.Rows.Cast(Of DataRow)()
Dim item As DataRow
For Each item In rows
parentId = CInt(item("parentcategoryi
Dim name As String = item("Name").ToString()
While parentId > 0
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
Listbox1.Items.Add(name)
Next
End If
create a member in your page class:
Dim MapCategory As New Dictionary(Of String, Integer)
in your SelectedIndexChanged:
Dim MapCategory As New Dictionary(Of String, Integer)
--page_onload
If Not (Page.IsPostBack) Then
Dim sqlConn As New SqlConnection
Dim strConn As String
Dim cmd As New SqlClient.SqlCommand
strConn = System.Configuration.ConfigurationManager.ConnectionStrings("JC").ConnectionString
sqlConn = New SqlConnection(strConn)
'Dim reader1, reader As SqlDataReader
cmd.Connection = sqlConn
sqlConn.Open()
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT [Id] ,[Name] ,[ParentCategoryId] FROM [nopCommerce].[dbo].[Category]", sqlConn)
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet, "Ordersvariant")
Dim dt As DataTable = dataSet.Tables(0)
Dim parentId As Integer = 0
' Dim list As New List(Of String)()
Dim rows = dt.Rows.Cast(Of DataRow)()
Dim item As DataRow
For Each item In rows
parentId = CInt(item("parentcategoryid"))
Dim name As String = item("Name").ToString()
While parentId > 0
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid"))
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
MapCategory.Add(name, parentId)
Listbox1.Items.Add(name)
Next
End If
in your SelectedIndexChanged:
Private Sub list_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles listBox1.SelectedIndexChanged
Dim curItem As String = Listbox1.SelectedItem.Value
--get parentid of selected item
Dim parentCatId As Integer = MapCategory(curItem))
Response.Write(parentCatId)
End If
End Sub
ASKER
thanks
im getting the following error in any of the selection of the dropdownlist
The given key was not present in the dictionary.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Collections.Generic .KeyNotFou ndExceptio n: The given key was not present in the dictionary.
Source Error:
Line 154:
Line 155: '--get parentid of selected item
Line 156: Dim parentCatId As Integer = MapCategory(curItem)
Line 157: Response.Write(parentCatId )
Line 158:
im getting the following error in any of the selection of the dropdownlist
The given key was not present in the dictionary.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Collections.Generic
Source Error:
Line 154:
Line 155: '--get parentid of selected item
Line 156: Dim parentCatId As Integer = MapCategory(curItem)
Line 157: Response.Write(parentCatId
Line 158:
on line 156, what is the value of curItem when the exception occurs>?
found a bug in the for each (line 34).
replace it with:
now, the map contains the following:
key: value:
A->B->C 2
while 2 is the parentid of A which is the id of B.
so each the selectedIndex change event will take the current select item from the list and using the map get its parent id.
replace it with:
For Each item In rows
dim orgParentId as Integer
orgParentId =parentId = CInt(item("parentcategoryid"))
Dim name As String = item("Name").ToString()
While parentId > 0
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid"))
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
MapCategory.Add(name, orgParentId )
Listbox1.Items.Add(name)
Next
now, the map contains the following:
key: value:
A->B->C 2
while 2 is the parentid of A which is the id of B.
so each the selectedIndex change event will take the current select item from the list and using the map get its parent id.
ASKER
Apparel & Shoes->Apparel accessories
testing11
etc.,
Dim curItem As String = Listbox1.SelectedItem.Valu e
Response.Write(curItem)
Response.End()
'--get parentid of selected item
Dim parentCatId As Integer = MapCategory(curItem)
Response.Write(parentCatId )
testing11
etc.,
Dim curItem As String = Listbox1.SelectedItem.Valu
Response.Write(curItem)
Response.End()
'--get parentid of selected item
Dim parentCatId As Integer = MapCategory(curItem)
Response.Write(parentCatId
ASKER
i have noticed all the values are 00000000000000000000
when i write Response.Write(parentId)
While parentId > 0
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid "))
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
MapCategory.Add(name, parentId)
Response.Write(parentId)
Listbox1.Items.Add(name)
'List.Items(parentId).Text = name
Next
when i write Response.Write(parentId)
While parentId > 0
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
MapCategory.Add(name, parentId)
Response.Write(parentId)
Listbox1.Items.Add(name)
'List.Items(parentId).Text
Next
did u update the code according to my last comment?
ASKER
yes.. the whole code is again..
If Not (Page.IsPostBack) Then
Dim sqlConn As New SqlConnection
Dim strConn As String
Dim cmd As New SqlClient.SqlCommand
strConn = System.Configuration.Confi gurationMa nager.Conn ectionStri ngs("JC"). Connection String
sqlConn = New SqlConnection(strConn)
'Dim reader1, reader As SqlDataReader
cmd.Connection = sqlConn
sqlConn.Open()
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT [Id] ,[Name] ,[ParentCategoryId] FROM [nopCommerce].[dbo].[Categ ory]", sqlConn)
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet, "Ordersvariant")
Dim dt As DataTable = dataSet.Tables(0)
Dim parentId As Integer = 0
' Dim list As New List(Of String)()
Dim rows = dt.Rows.Cast(Of DataRow)()
Dim item As DataRow
For Each item In rows
parentId = CInt(item("parentcategoryi d"))
Dim name As String = item("Name").ToString()
Response.Write(parentId)
While parentId > 0
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid "))
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
MapCategory.Add(name, parentId)
Response.Write("<BR>" & parentId)
Listbox1.Items.Add(name)
Next
End If
---------------
Private Sub list_SelectedIndexChanged( ByVal sender As Object, ByVal e As System.EventArgs) Handles listBox1.SelectedIndexChan ged
Dim curItem As String = Listbox1.SelectedItem.Valu e
Response.Write(curItem)
Response.End()
'--get parentid of selected item
Dim parentCatId As Integer = MapCategory(curItem)
Response.Write(parentCatId )
If Not (Page.IsPostBack) Then
Dim sqlConn As New SqlConnection
Dim strConn As String
Dim cmd As New SqlClient.SqlCommand
strConn = System.Configuration.Confi
sqlConn = New SqlConnection(strConn)
'Dim reader1, reader As SqlDataReader
cmd.Connection = sqlConn
sqlConn.Open()
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT [Id] ,[Name] ,[ParentCategoryId] FROM [nopCommerce].[dbo].[Categ
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet, "Ordersvariant")
Dim dt As DataTable = dataSet.Tables(0)
Dim parentId As Integer = 0
' Dim list As New List(Of String)()
Dim rows = dt.Rows.Cast(Of DataRow)()
Dim item As DataRow
For Each item In rows
parentId = CInt(item("parentcategoryi
Dim name As String = item("Name").ToString()
Response.Write(parentId)
While parentId > 0
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
MapCategory.Add(name, parentId)
Response.Write("<BR>" & parentId)
Listbox1.Items.Add(name)
Next
End If
---------------
Private Sub list_SelectedIndexChanged(
Dim curItem As String = Listbox1.SelectedItem.Valu
Response.Write(curItem)
Response.End()
'--get parentid of selected item
Dim parentCatId As Integer = MapCategory(curItem)
Response.Write(parentCatId
u didn't replace the for each loop with the code i've posted:
If Not (Page.IsPostBack) Then
Dim sqlConn As New SqlConnection
Dim strConn As String
Dim cmd As New SqlClient.SqlCommand
strConn = System.Configuration.ConfigurationManager.ConnectionStrings("JC").ConnectionString
sqlConn = New SqlConnection(strConn)
'Dim reader1, reader As SqlDataReader
cmd.Connection = sqlConn
sqlConn.Open()
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT [Id] ,[Name] ,[ParentCategoryId] FROM [nopCommerce].[dbo].[Category]", sqlConn)
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet, "Ordersvariant")
Dim dt As DataTable = dataSet.Tables(0)
Dim parentId As Integer = 0
' Dim list As New List(Of String)()
Dim rows = dt.Rows.Cast(Of DataRow)()
Dim item As DataRow
For Each item In rows
Dim orgParentId as Integer
orgParentId =parentId = CInt(item("parentcategoryid"))
Dim name As String = item("Name").ToString()
While parentId > 0
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid"))
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
MapCategory.Add(name, orgParentId )
Response.Write("<BR>" & parentId)
Listbox1.Items.Add(name)
Next
End If
ASKER
change:
Response.Write("<BR>" & parentId)
with:
Response.Write("<BR>" & parentId)
Response.Write("<BR>" & name)
what is printed?
Response.Write("<BR>" & parentId)
with:
Response.Write("<BR>" & parentId)
Response.Write("<BR>" & name)
what is printed?
ASKER
thanks.. it is printing like this below
0
Books
0
Computers
0
Desktops
0
Notebooks
0
Accessories
0
Software
0
Games
0
Electronics
0
Camera, photo
0
Cell phones
0
Apparel & Shoes
0
Shirts
0
Jeans
0
Shoes
0
Apparel accessories
0
Digital downloads
0
Jewelry
0
Gift Cards
0
Battery
0
testing11
0
tsting12
0
tsting12ww
0
tsting12wwee
0
tsting12wwees
0
battery23232
0
3rd
0
testing2323
0
Hello Group
0
Books
0
Computers
0
Desktops
0
Notebooks
0
Accessories
0
Software
0
Games
0
Electronics
0
Camera, photo
0
Cell phones
0
Apparel & Shoes
0
Shirts
0
Jeans
0
Shoes
0
Apparel accessories
0
Digital downloads
0
Jewelry
0
Gift Cards
0
Battery
0
testing11
0
tsting12
0
tsting12ww
0
tsting12wwee
0
tsting12wwees
0
battery23232
0
3rd
0
testing2323
0
Hello Group
i reviewd the code few times i dont understand whats wrong.
under this line:
While parentId > 0
add:
Response.Write("<BR>" & name)
and remove the other Response.Write() lines.
what is it printing?
under this line:
While parentId > 0
add:
Response.Write("<BR>" & name)
and remove the other Response.Write() lines.
what is it printing?
ASKER
I have added the below after While parentId > 0, but I feel. nothing is getting display..
While parentId > 0
Response.Write("<BR>jjjj" & name)
thanks
While parentId > 0
Response.Write("<BR>jjjj" & name)
thanks
that means parentId is always 0 for all rows.
check line 34:
orgParentId =parentId = CInt(item("parentcategoryi d"))
parentId is always 0 which means the datatable has wrong values for parentcategoryid.
i'd check in DB that parentcategoryid is not 0 for all rows.
then run the query in your DB and see that the results are correct.
add those lines:
under
check line 34:
orgParentId =parentId = CInt(item("parentcategoryi
parentId is always 0 which means the datatable has wrong values for parentcategoryid.
i'd check in DB that parentcategoryid is not 0 for all rows.
then run the query in your DB and see that the results are correct.
add those lines:
Dim ids = String.Join(",", dt.Rows.Cast(Of DataRow)().[Select](Function(n) n("ParentCategoryId")).ToArray())
Response.Write("<BR>ids: " & ids )
under
Dim dt As DataTable = dataSet.Tables(0)
ASKER
Im getting the values
ids: 0,0,2,2,2,2,2,0,8,8,0,11,1 1,11,11,0, 0,0,0,0,0, 0,0,0,20,2 5,19,27
-------------------------- ---------- ----------
The full code is
If Not (Page.IsPostBack) Then
Dim sqlConn As New SqlConnection
Dim strConn As String
Dim cmd As New SqlClient.SqlCommand
strConn = System.Configuration.Confi gurationMa nager.Conn ectionStri ngs("JC"). Connection String
sqlConn = New SqlConnection(strConn)
'Dim reader1, reader As SqlDataReader
cmd.Connection = sqlConn
sqlConn.Open()
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT [Id] ,[Name] ,[ParentCategoryId] FROM [nopCommerce].[dbo].[Categ ory]", sqlConn)
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet, "Ordersvariant")
Dim dt As DataTable = dataSet.Tables(0)
Dim ids = String.Join(",", dt.Rows.Cast(Of DataRow)().[Select](Functi on(n) n("ParentCategoryId")).ToA rray())
Response.Write("<BR>ids: " & ids)
Dim parentId As Integer = 0
' Dim list As New List(Of String)()
Dim rows = dt.Rows.Cast(Of DataRow)()
Dim item As DataRow
For Each item In rows
Dim orgParentId As Integer
orgParentId = parentId = CInt(item("parentcategoryi d"))
Dim name As String = item("Name").ToString()
While parentId > 0
Response.Write("<BR>jjjj" & name)
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid "))
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
MapCategory.Add(name, orgParentId)
'Response.Write("<BR>" & parentId)
'Response.Write("<BR>" & name)
Listbox1.Items.Add(name)
Next
End If
ids: 0,0,2,2,2,2,2,0,8,8,0,11,1
--------------------------
The full code is
If Not (Page.IsPostBack) Then
Dim sqlConn As New SqlConnection
Dim strConn As String
Dim cmd As New SqlClient.SqlCommand
strConn = System.Configuration.Confi
sqlConn = New SqlConnection(strConn)
'Dim reader1, reader As SqlDataReader
cmd.Connection = sqlConn
sqlConn.Open()
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT [Id] ,[Name] ,[ParentCategoryId] FROM [nopCommerce].[dbo].[Categ
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet, "Ordersvariant")
Dim dt As DataTable = dataSet.Tables(0)
Dim ids = String.Join(",", dt.Rows.Cast(Of DataRow)().[Select](Functi
Response.Write("<BR>ids: " & ids)
Dim parentId As Integer = 0
' Dim list As New List(Of String)()
Dim rows = dt.Rows.Cast(Of DataRow)()
Dim item As DataRow
For Each item In rows
Dim orgParentId As Integer
orgParentId = parentId = CInt(item("parentcategoryi
Dim name As String = item("Name").ToString()
While parentId > 0
Response.Write("<BR>jjjj" & name)
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
MapCategory.Add(name, orgParentId)
'Response.Write("<BR>" & parentId)
'Response.Write("<BR>" & name)
Listbox1.Items.Add(name)
Next
End If
ok so datatable is fine.
under For Each item In rows
put Response.Write("<BR>" & CInt(item("ParentCategoryI d")))
under For Each item In rows
put Response.Write("<BR>" & CInt(item("ParentCategoryI
ASKER
im getting this values.. thanks
0
0
0
0
0
0
0
0
20
25
19
27
0
0
0
0
0
0
0
0
20
25
19
27
so maybe it's case sensitive, change
orgParentId = parentId = CInt(item("parentcategoryi d"))
to
orgParentId = parentId = CInt(item("ParentCategoryI d"))
orgParentId = parentId = CInt(item("parentcategoryi
to
orgParentId = parentId = CInt(item("ParentCategoryI
ASKER
after copy paste, here is the full code..
but still the drop down values are plainvalues
If Not (Page.IsPostBack) Then
Dim sqlConn As New SqlConnection
Dim strConn As String
Dim cmd As New SqlClient.SqlCommand
strConn = System.Configuration.Confi gurationMa nager.Conn ectionStri ngs("JC"). Connection String
sqlConn = New SqlConnection(strConn)
'Dim reader1, reader As SqlDataReader
cmd.Connection = sqlConn
sqlConn.Open()
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT [Id] ,[Name] ,[ParentCategoryId] FROM [nopCommerce].[dbo].[Categ ory]", sqlConn)
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet, "Ordersvariant")
Dim dt As DataTable = dataSet.Tables(0)
Dim ids = String.Join(",", dt.Rows.Cast(Of DataRow)().[Select](Functi on(n) n("ParentCategoryId")).ToA rray())
'Response.Write("<BR>ids: " & ids)
Dim parentId As Integer = 0
' Dim list As New List(Of String)()
Dim rows = dt.Rows.Cast(Of DataRow)()
Dim item As DataRow
For Each item In rows
' Response.Write("<BR>" & CInt(item("ParentCategoryI d")))
Dim orgParentId As Integer
orgParentId = parentId = CInt(item("ParentCategoryI d"))
Dim name As String = item("Name").ToString()
While parentId > 0
' Response.Write("<BR>jjjj" & name)
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid "))
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
MapCategory.Add(name, orgParentId)
'Response.Write("<BR>" & parentId)
'Response.Write("<BR>" & name)
Listbox1.Items.Add(name)
Next
End If
Untitled-picture1.png
but still the drop down values are plainvalues
If Not (Page.IsPostBack) Then
Dim sqlConn As New SqlConnection
Dim strConn As String
Dim cmd As New SqlClient.SqlCommand
strConn = System.Configuration.Confi
sqlConn = New SqlConnection(strConn)
'Dim reader1, reader As SqlDataReader
cmd.Connection = sqlConn
sqlConn.Open()
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT [Id] ,[Name] ,[ParentCategoryId] FROM [nopCommerce].[dbo].[Categ
Dim dataSet As DataSet = New DataSet()
adapter.Fill(dataSet, "Ordersvariant")
Dim dt As DataTable = dataSet.Tables(0)
Dim ids = String.Join(",", dt.Rows.Cast(Of DataRow)().[Select](Functi
'Response.Write("<BR>ids: " & ids)
Dim parentId As Integer = 0
' Dim list As New List(Of String)()
Dim rows = dt.Rows.Cast(Of DataRow)()
Dim item As DataRow
For Each item In rows
' Response.Write("<BR>" & CInt(item("ParentCategoryI
Dim orgParentId As Integer
orgParentId = parentId = CInt(item("ParentCategoryI
Dim name As String = item("Name").ToString()
While parentId > 0
' Response.Write("<BR>jjjj" & name)
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid
name = String.Format("{0}->{1}", row("Name"), name)
End If
End While
MapCategory.Add(name, orgParentId)
'Response.Write("<BR>" & parentId)
'Response.Write("<BR>" & name)
Listbox1.Items.Add(name)
Next
End If
Untitled-picture1.png
change:
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid "))
name = String.Format("{0}->{1}", row("Name"), name)
End If
to
If row IsNot Nothing Then
parentId = CInt(row("ParentCategoryId "))
name = String.Format("{0}->{1}", row("Name"), name)
End If
If row IsNot Nothing Then
parentId = CInt(row("parentcategoryid
name = String.Format("{0}->{1}", row("Name"), name)
End If
to
If row IsNot Nothing Then
parentId = CInt(row("ParentCategoryId
name = String.Format("{0}->{1}", row("Name"), name)
End If
For Each item In rows
Dim orgParentId As Integer
orgParentId = parentId = CInt(item("ParentCategoryId"))
Dim name As String = item("Name").ToString()
While parentId > 0
Dim row = rows.Where(Function(n) CInt(n("Id")) = parentId).FirstOrDefault()
If row IsNot Nothing Then
parentId = CInt(row("ParentCategoryId"))
name = String.Format("{0}->{1}", row("Name"), name)
Response.Write("<BR>" & name & parentId)
End If
End While
MapCategory.Add(name, orgParentId)
Listbox1.Items.Add(name)
Next
ASKER
still the same plain dropdown values instead of ->
and when i click the selected index event
Server Error in '/' Application.
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
The given key was not present in the dictionary.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Collections.Generic .KeyNotFou ndExceptio n: The given key was not present in the dictionary.
Source Error:
Line 221:
Line 222: '--get parentid of selected item
Line 223: Dim parentCatId As Integer = MapCategory(curItem)
Line 224: Response.Write(parentCatId )
Line 225:
and when i click the selected index event
Server Error in '/' Application.
--------------------------
The given key was not present in the dictionary.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Collections.Generic
Source Error:
Line 221:
Line 222: '--get parentid of selected item
Line 223: Dim parentCatId As Integer = MapCategory(curItem)
Line 224: Response.Write(parentCatId
Line 225:
this is .net so u should be able to debug your code.
i run this on my app few times and i couldn't figure out what's the problem.
in my last post i cleaned up all the response.write() besides the on on line 14.
Response.Write("<BR>" & name & parentId)
put breakpoint there and check if the name is being concatenated with the parent names.
the logic is that for each row we take the id and we look for the row of its parent using the ParentCategoryId (line 9), untill parentid equals 0.
then we move to the next row.
while doing so we concatenate the name and the parent name separated by -> (line 13)
i run this on my app few times and i couldn't figure out what's the problem.
in my last post i cleaned up all the response.write() besides the on on line 14.
Response.Write("<BR>" & name & parentId)
put breakpoint there and check if the name is being concatenated with the parent names.
the logic is that for each row we take the id and we look for the row of its parent using the ParentCategoryId (line 9), untill parentid equals 0.
then we move to the next row.
while doing so we concatenate the name and the parent name separated by -> (line 13)
ASKER
ok .. no issues.. I will debug and come back to you on this..
1. totally differnt query: I want to display categroy, subcategories,.. in the treeview..
2.
. i want to dispaly the data in the gridview based on the Id, is being fetched on the data row..event
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT [Id] ,[Name] ,[ParentCategoryId] FROM [nopCommerce].[dbo].[Categ ory] where id=" & e.Row.Cells(0).Text, sqlConn)
1. totally differnt query: I want to display categroy, subcategories,.. in the treeview..
2.
. i want to dispaly the data in the gridview based on the Id, is being fetched on the data row..event
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT [Id] ,[Name] ,[ParentCategoryId] FROM [nopCommerce].[dbo].[Categ
asp treeview?
ASKER
asp.net 2/3.5 treeview.. yes..
ASKER
still waiting for your solution.. thanks
Please close this thread and open new question about the treeview
10x
10x
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
u forgot to reward the points, 10x
10x again for the points.
ASKER
good support
>>Input string was not in a correct format. -> this exception occurs because the item cannot be converted to integer.
so what is the value of the item when the exception rises?