DropDown in ListView

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

I need to populate a DropDownList when going into Insert mode on a ListView.
I have done this several times in a GridView or FormView but cannot get it
to work in a ListView. Below is my ItemDatabound code and the control named
ddlExpenseID is not getting filled. Can anyone help?
p.s. i need in both Insert and Edit. Thanks.

David

Protected Sub lvIncExpTrans_ItemDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles
lvIncExpTrans.ItemDataBound
Dim tb As TextBox
Dim ddl As DropDownList
If e.Item.ItemType = ListViewItemType.DataItem Then
If Not e.Item.FindControl("ddlExpenseID") Is Nothing Then
' In edit or insert so get values for DropDownLists
' Get contents of dropdownlists and populate
ddl = CType(e.Item.FindControl("ddlExpenseID"),
DropDownList)
ddl.DataSource = LookupClass.GetExpenseTypes()
ddl.DataValueField = "ExpenseID"
ddl.DataTextField = "Expense"
ddl.DataBind()
End If
End If
End Sub
 
I need to populate a DropDownList when going into Insert mode on a ListView.
I have done this several times in a GridView or FormView but cannot get it
to work in a ListView.  Below is my ItemDatabound code and the control named
ddlExpenseID is not getting filled. Can anyone help?
p.s. i need in both Insert and Edit.  Thanks.

David

    Protected Sub lvIncExpTrans_ItemDataBound(ByVal sender As Object,ByVal
e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles
lvIncExpTrans.ItemDataBound
        Dim tb As TextBox
        Dim ddl As DropDownList
        If e.Item.ItemType = ListViewItemType.DataItem Then
            If Not e.Item.FindControl("ddlExpenseID") Is Nothing Then
                ' In edit or insert so get values for DropDownLists
                ' Get contents of dropdownlists and populate
                ddl = CType(e.Item.FindControl("ddlExpenseID"),
DropDownList)
                ddl.DataSource = LookupClass.GetExpenseTypes()
                ddl.DataValueField = "ExpenseID"
                ddl.DataTextField = "Expense"
                ddl.DataBind()
             End If
        End If
    End Sub

Are you sure that this method is executed? The code looks correct to
me.
 
I need to populate a DropDownList when going into Insert mode on a
ListView.
I have done this several times in a GridView or FormView but cannot get it
to work in a ListView. Below is my ItemDatabound code and the control
named
ddlExpenseID is not getting filled. Can anyone help?
p.s. i need in both Insert and Edit. Thanks.

David

Protected Sub lvIncExpTrans_ItemDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles
lvIncExpTrans.ItemDataBound
Dim tb As TextBox
Dim ddl As DropDownList
If e.Item.ItemType = ListViewItemType.DataItem Then
If Not e.Item.FindControl("ddlExpenseID") Is Nothing Then
' In edit or insert so get values for DropDownLists
' Get contents of dropdownlists and populate
ddl = CType(e.Item.FindControl("ddlExpenseID"),
DropDownList)
ddl.DataSource = LookupClass.GetExpenseTypes()
ddl.DataValueField = "ExpenseID"
ddl.DataTextField = "Expense"
ddl.DataBind()
End If
End If
End Sub

Are you sure that this method is executed? The code looks correct to
me.


What would keep ItemDatabound from executing? The ListView is displaying
data so I assume it is running every page load. Am I missing something? Or
need to look elsewhere? Thanks.

David
 
Are you sure that this method is executed? The code looks correct to
me.

What would keep ItemDatabound from executing?  The ListView is displaying
data so I assume it is running every page load.  Am I missing something? Or
need to look elsewhere?  Thanks.

David- Hide quoted text -

- Show quoted text -

Hi David,

For instance, you can dynamically remove eventhandlers using
RemoveHandler, but I suppose this is not the case. Just try to debug
and set a breakpoint in that method, or add a test output to the page.

If method does work then either ddlExpenseID is not there (a line with
FindControl("ddlExpenseID")) or LookupClass.GetExpenseTypes returns
nothing.

Hope this helps
 
Back
Top