DropDownList not displaying properly solution

J

Jim French

I thought I would share this (semi) annoying issue I had. Basically, the
DropDownList I was trying to bind inside a Repeater with the ItemDataBound
event was not working - instead of a normal listbox, I was getting a row of
string values. The problem was that I left out the closing '>' from the
literal control that was directly in front of the DDL.

Private Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
Repeater1.ItemDataBound
'Bind Name
CType(e.Item.FindControl("litName"), Literal).Text = "<p><b>" &
objDS.Tables("Table2").Rows(e.Item.ItemIndex).Item("personame") & "</b></p"
<-----

'Bind DropDownList
Dim lstWho As DropDownList = CType(e.Item.FindControl("lstwho"),
DropDownList)
lstWho.DataSource = objDS.Tables("Table1")
lstWho.DataTextField = "Name"
lstWho.DataValueField = "ID"
lstWho.DataBind()
End Sub

Hope that can help someone save some time someday!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top