Trouble Filling DropDownList in Datagrid

D

David Londeck

The following code will only populate every row for the DropDownList control
column in the datagrid instead of every row where the DropDownList appears
in the DataGrid for a particular column. Any ideas on why?

Private Sub dgAssignSalesReptoIMEI_ItemDataBound(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgAssignSalesReptoIMEI.ItemDataBound

If dtSalesRep Is Nothing Then
' This will make a trip to the Database
dtSalesRep = FilldgDropDownList()
End If

If e.Item.ItemType = ListItemType.Item Then

Dim DRV As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim DropDown As String = DRV("REPID")

Dim ddl As DropDownList = _
CType(e.Item.FindControl("ddlSalesRep"), DropDownList)
Dim Item As ListItem

' Fill grid
' if dtSalesRep is globally defined then we save the trip to the
database
ddl.DataSource = dtSalesRep
ddl.DataTextField = "RepName"
ddl.DataValueField = "RepID"

ddl.DataBind()
ddl.Items.Insert(0, "Unassigned")
ddlDefaultValue.text = drv.("RepID")

Item = ddl.Items.FindByValue(DropDown)
' If this item is not null then select the item
If Not Item Is Nothing Then Item.Selected = True
End If
End Sub
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top