views:

1147

answers:

2

I'm missing something here, but I've stared at it too long to see it. I've got a simple ListView, with the typical Edit/Update/Cancel buttons. I've got the following set up in my EditITemTemplate when the row goes into edit mode:

<EditItemTemplate>
    <asp:Label ID="AccountIdLabel" runat="server" Text='<%#Eval("lan_id")%>' />
    <asp:TextBox ID="EmployeeIdTextBox" runat="server" Text='<%#Eval("emp_id")%>' Columns="5" />
</EditItemTemplate>

At this point the user types a value in the EmployeeIdTextBox. When they press Update, it's trying to do the following:

Private Sub ListView_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewUpdateEventArgs) Handles EmployeeListView.ItemUpdating

    Dim accountId = CType(EmployeeListView.EditItem.FindControl("AccountIdLabel"), Label).Text
    Dim employeeId = CType(EmployeeListView.EditItem.FindControl("EmployeeIdTextBox"), TextBox).Text

    UpdateMap(accountId, employeeId)

    EmployeeListView.EditIndex = -1
    GetData()

End Sub

The problem is that "employeeId" is coming back with the original value in the text box, not what the user entered. What am I missing?

UPDATE: Found it. As usual, caused by other code not included here in an effort to ask a simple question. :)

A: 

I think this is because the ItemUpdating event fires before the ListView updates the record. You probably want to put this code in the ItemUpdated event instead.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemupdating.aspx

Kevin Tighe
A: 

Found it - I had code in the ItemCommand event that was handling other events, but it was doing the GetData() at the end regardless of the command, so basically the data was being refreshed right before the ItemUpdating event fired. I tightened up ItemCommand, and it's now working as expected.

gfrizzle