omencat
omencat

Reputation: 1165

Update asp.net listview with LINQ, programmatically

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();
    }

Upvotes: 0

Views: 862

Answers (1)

Ritik Khatwani
Ritik Khatwani

Reputation: 549

You can get the ID from the event arguments either like

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

depending on your situation.

Upvotes: 1

Related Questions