i want to have 2 listbox. the first listbox is for the Main category and the other one is for the sub category. and by using sql 2005 for the database. help me plz. . .

for example my main category for the 1st listbox is
ADIDAS
CONVERSE
NIKE
SKETCHERS

and when i click one of the main categories it will
output the sub categories to the 2nd listbox.

i want to have 2 listbox. the first listbox is for the Main category and the other one is for the sub category. and by using sql 2005 for the database. help me plz. . .

for example my main category for the 1st listbox is
ADIDAS
CONVERSE
NIKE
SKETCHERS

and when i click one of the main categories it will
output the sub categories to the 2nd listbox.

Hi y0yie

To populate in listbox refer to the sample below:

lstboxName.DataSource = 'Here comes the datasource(dataset or any) you assign to the listbox.
lstboxName.DataValueField = "" 'Assign the column value that will be passed on selection.
lstboxName.DataTextField = "" 'Assign the column text that will be displayed in the listbox.
lstboxName.DataBind()

For fetching the selected items and passing to query refer to the sample below:

Dim selectedItem As String

If lstboxName.Items.Count > 0 Then
For i = 0 To lstboxName.Items.Count - 1
If lstboxName.Items(i).Selected Then
selectedItem = selectedItem + lstboxName.Items(i).Value.Trim() & ","
End If
Next
End If

Dim selectedItemSplit As String() = selectedItem.ToString().Split(",")

Now pass the selectedItemSplit value either by as array or even you can pass with comma seperated as contained in selectedItem and pass to the select query and then populate it to the second listbox based on the selected value(s) in the first listbox.

Hope this helps!!!

Mark as "solved" if this helps to solve your requirement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.