0

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 Answer 1

1

You can get the ID from the event arguments either like

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

depending on your situation.

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.