views:

29

answers:

1

I'm trying to find a good code sample to update a database entry in my listview control. I suppose I would need to extract the ID from somewhere (some label control?). I am using LINQtoSQL to talk with the database.

        protected void lvTargets_ItemUpdating(object sender, ListViewUpdateEventArgs e)
    {
        InventoryDataContext inventory = new InventoryDataContext();

        //Target target = from target in inventory.Targets
        //                where target.ID == lvTargets.Items[e.ItemIndex].FindControl("ID")
        // *** Not sure how to go about this ^^^

        //inventory.Targets.InsertOnSubmit(target);
        //inventory.SubmitChanges();


        lvTargets.EditIndex = -1;
        BindInventory();
    }
+1  A: 

You can get the ID from the event arguments either like

e.Keys["ID"]
e.OldValues["ID"]

depending on your situation.

Ritik Khatwani
I have this now:Target target = (from t in inventory.Targets where t.ID == (int)e.Keys["ID"] select t).Single();Now I need to determine how to update the target object with the values and submit changes to the db.target.Barcode = Convert.ToInt32(lvTargets.Items[e.ItemIndex].FindControl("BarcodeTextBox"));How do I access the values of the textboxes in thed EditItemTemplate?
Bay Wolf