DropDown in ListView

Discussion in 'ASP .Net' started by David C, Sep 30, 2009.

  1. David C

    David C 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
    David C, Sep 30, 2009
    #1
    1. Advertising

  2. On Sep 30, 9:31 pm, "David C" <> wrote:
    > 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.
    Alexey Smirnov, Oct 1, 2009
    #2
    1. Advertising

  3. David C

    David C Guest

    "Alexey Smirnov" <> wrote in message
    news:...
    On Sep 30, 9:31 pm, "David C" <> wrote:
    > 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
    David C, Oct 1, 2009
    #3
  4. On Oct 1, 11:37 pm, "David C" <> wrote:
    > "Alexey Smirnov" <> wrote in message
    >
    > news:...
    > On Sep 30, 9:31 pm, "David C" <> wrote:
    >
    >
    >
    >
    >
    > > 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- 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
    Alexey Smirnov, Oct 2, 2009
    #4
    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. vishnu
    Replies:
    1
    Views:
    1,202
    Patrick.O.Ige
    Mar 25, 2006
  2. Mike
    Replies:
    1
    Views:
    802
  3. acadam
    Replies:
    0
    Views:
    754
    acadam
    Dec 27, 2006
  4. Satheesh
    Replies:
    0
    Views:
    2,483
    Satheesh
    Sep 17, 2008
  5. .
    Replies:
    0
    Views:
    718
Loading...

Share This Page