DropDown in ListView

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
 
G

Guest

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.
 
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

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
 
G

Guest

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
 

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,818
Messages
2,569,727
Members
45,664
Latest member
Phil79581

Latest Threads

Top