ListView insert - no current records

D

David C

I have a ListView that I am using to edit and insert rows into a database
table. I am displaying records for a specific person and existing records
edit and update fine. Also, if a person already has records in that table,
the ListView DropDownList population and insert works fine. The problem is
that when a person has no records in the table (ListView is empty) the
DropDownLists are not getting populated. I assume maybe because the DDL
populating is being done in the ItemDataBound event? If so, where is the
best place to populate the dropdowns for insert? Below is some of the code
in my ItemDataBound event used to populate the DDL's. Thanks.

David

Protected Sub lvClientExpenses_ItemDataBound(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles
lvClientExpenses.ItemDataBound
Dim ddl As DropDownList
Dim intExpenseID As Int32 = 0
Dim intBranch As Int16 = 0

'Get the item and row objects.
Dim dataItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
Dim rowView As DataRowView = CType(dataItem.DataItem, DataRowView)

' Retrieve the PeopleLinkID value for the current item.
Dim intPeopleLinkID As Int32 =
Convert.ToInt32(rowView("PeopleLinkID"))

'Verify there is an item being edited.
If lvClientExpenses.EditIndex >= 0 Then
' Check for an item in edit mode.
If dataItem.DisplayIndex = lvClientExpenses.EditIndex Then
...code is here to load dropdowns for edit
End If
Else
If lvClientExpenses.InsertItemPosition =
InsertItemPosition.FirstItem Then
'showing insert row
If e.Item.ItemType = ListViewItemType.DataItem Then
ddl =
lvClientExpenses.InsertItem.FindControl("ddlExpenseID")
ddl.DataSource = LookupClass.GetExpenseTypes()
ddl.DataValueField = "ExpenseID"
ddl.DataTextField = "Expense"
ddl.DataBind()
ddl.Items.Insert(0, New ListItem("", ""))

ddl =
lvClientExpenses.InsertItem.FindControl("ddlPayeeID")
ddl.DataSource =
LookupClass.GetClientPastPayees(intPeopleLinkID)
ddl.DataValueField = "PayeeID"
ddl.DataTextField = "Payee"
ddl.DataBind()
ddl.Items.Insert(0, New ListItem("", ""))
End If
End If
End If

End Sub
 

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,836
Messages
2,569,747
Members
45,545
Latest member
rapter____0

Latest Threads

Top