简体   繁体   English

使用LINQ以编程方式更新asp.net列表视图

[英]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. 我试图找到一个好的代码示例来更新我的listview控件中的数据库条目。 I suppose I would need to extract the ID from somewhere (some label control?). 我想我需要从某个地方(某些标签控件?)提取ID。 I am using LINQtoSQL to talk with the database. 我正在使用LINQtoSQL与数据库交谈。

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

You can get the ID from the event arguments either like 您可以从事件参数中获取ID,例如

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

depending on your situation. 根据您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM