【问题标题】:Update asp.net listview with LINQ, programmatically以编程方式使用 LINQ 更新 asp.net listview
【发布时间】:2010-07-07 21:49:30
【问题描述】:

我正在尝试找到一个好的代码示例来更新我的列表视图控件中的数据库条目。我想我需要从某个地方提取 ID(一些标签控件?)。我正在使用 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();
    }

【问题讨论】:

    标签: c# asp.net linq linq-to-sql listview


    【解决方案1】:

    您可以从事件参数中获取 ID,例如

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

    取决于你的情况。

    【讨论】:

    • 我现在有这个:Target target = (from t in inventory.Targets where t.ID == (int)e.Keys["ID"] select t).Single();现在我需要确定如何使用值更新目标对象并将更改提交到数据库。 target.Barcode = Convert.ToInt32(lvTargets.Items[e.ItemIndex].FindControl("BarcodeTextBox"));如何访问 EditItemTemplate 中文本框的值?
    猜你喜欢
    • 2013-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-08
    • 1970-01-01
    相关资源
    最近更新 更多