I have a rather odd problem. I have an editable ListView, however – when I click edit I usually get the NullreferenceException once I try to get the textboxes. BUT the error is not consistent, sometimes it is there, sometimes not. I’m confused.
This is the code snippit:
public void test_ItemEditing(Object sender, ListViewEditEventArgs e)
{
// Liest die SpeiseID mit der die Daten aus der Datenbank extrahiert werden können
DataKey currentDataKey = speiseplanListView.DataKeys[e.NewEditIndex];
TextBox editDatum = (TextBox)speiseplanListView.EditItem.FindControl("txtDatum");
}
this is the asp.net file:
<EditItemTemplate>
<tr>
<td><asp:TextBox ID="txtDatum" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txtSpeise" runat="server"></asp:TextBox></td>
</tr>
</EditItemTemplate>
replace your
test_ItemEditingcode with below oneand handle the
test_ItemUpdatingevent for finding the control and updating the data.