Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through Multiple Dropdowns with different ID's but same elemen

Status
Not open for further replies.

MayoorPatel

Programmer
Apr 10, 2006
35
GB
Hi there I have a category and subcategory dropdown on my form as follows


However I want to have another 4 of these with different ID's. The code used to set the selected item is as follows

Code:
If Not ds.Tables(2).Rows.Count = 0 Then
            drpMainCategory.Items.FindByValue(ds.Tables(2).Rows(0)("num")).Selected = True
            Utility.PopulateSubCategory(drpMainSubCategory, ds.Tables(2).Rows(0)("num"))
            For Each row As DataRow In ds.Tables(2).Rows
                drpMainSubCategory.Items.FindByValue(row("subcategoryid")).Selected = True
            Next
        End If

Can somebody reccomend how I could amend my code to cater for multiple dropdowns with similar names ID's for instance the category dropdown is called drpMainCategory and the subcategory is called drpMainSubCategory. I want to name the others

drpMainCategory1, drpMainCategory2, drpMainCategory3, drpMainCategory4, drpMainCategory5

drpMainSubCategory1, drpMainSubCategory2, drpMainSubCategory3, drpMainSubCategory4, drpMainSubCategory5

I will also have to change the structure of my database so that the tables show the dropdown ID of the subcategory but for now I just want to know how to loop through the dropdown elements.

Thanks
 
Just use the FindControl method to get a reference to the relevant control


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top