Trouble Filling DropDownList in Datagrid

Discussion in 'ASP .Net Web Controls' started by David Londeck, Mar 28, 2005.

  1. 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
     
    David Londeck, Mar 28, 2005
    #1
    1. Advertising

  2. David Londeck

    Brock Allen Guest

    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
     
    Brock Allen, Mar 28, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. thegame
    Replies:
    1
    Views:
    961
    =?Utf-8?B?ZGlyazQx?=
    Feb 28, 2005
  2. tshad

    Error filling DropdownList

    tshad, Nov 11, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    773
    =?Utf-8?B?dGlta2xpbmc=?=
    Nov 12, 2005
  3. DavidC
    Replies:
    2
    Views:
    1,779
    DavidC
    Jan 18, 2010
  4. Mohsen Pahlevanzadeh
    Replies:
    0
    Views:
    146
    Mohsen Pahlevanzadeh
    Sep 9, 2013
  5. MRAB
    Replies:
    0
    Views:
    133
Loading...

Share This Page