Click to See Complete Forum and Search --> : Html Databound Drop Down List


Nate1
10-31-2007, 10:52 PM
U Have a databound drop down list that I want to edit the output data befroe its displayed like the ItemDatabound function, so instead of having the output

Category One
Category Two
Category Three

I can call a function to count the numbers in each category

Category One (16)
Category Two (25)
Category Three (45)

Is it possible to do this?


Protected Sub GetParentCategories()

Dim SearchString As String = "SELECT iCategory_Name as Names,iCategoryID as ID " _
& " FROM Trade_Category " _
& " WHERE iParent_Category = 0 AND bIsUsed = 1" _
& " UNION ALL" _
& " Select sName as Names, iFreeID as ID" _
& " FROM FreeCategory" _
& " WHERE iParent = 0 AND bIsUsed = 1 Order by Names ASC"
Dim daParents As SqlDataAdapter = New SqlDataAdapter(SearchString, Connection())
daParents.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim cb As New SqlCommandBuilder(daParents)

' === create a new dataset ===
Dim dsParents As DataSet = New DataSet

Try
' === fill dataset ===
daParents.Fill(dsParents, "Names")
Catch ex As Exception
'record an Error?
End Try

' === Clean Up ===
daParents.Dispose()
cb.Dispose()


ddlParentCategory.DataSource = dsParents
ddlParentCategory.DataMember = "Names"
ddlParentCategory.DataTextField = "Names"
ddlParentCategory.DataValueField = "ID"
ddlParentCategory.DataBind()

Dim item As New ListItem()
item.Text = "any category .."
item.Value = 0
ddlParentCategory.Items.Insert(0, item)
End Sub