Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Trouble Filling DropDownList in Datagrid

Reply
Thread Tools

Trouble Filling DropDownList in Datagrid

 
 
David Londeck
Guest
Posts: n/a
 
      03-28-2005
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


 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      03-28-2005
You should also check for:

e.Item.ItemType = ListItemType.AlternatingItem

-Brock
DevelopMentor
http://staff.develop.com/ballen



> 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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error filling DropDownList on ListView DavidC ASP .Net 2 01-18-2010 08:13 PM
dropdownlist not filling up? Joris De Groote ASP General 2 04-18-2006 12:55 PM
Error filling DropdownList tshad ASP .Net 5 11-12-2005 05:36 AM
Filling One DataGrid Based on Selection from Another DataGrid - Both in Separate User Controls thegame ASP .Net 1 02-28-2005 04:23 PM
filling values to dropdownlist using javascript at page load time deepak kumar ASP .Net Web Controls 13 11-05-2004 02:26 AM



Advertisments