【问题标题】:Web Control CRUD operations on Telerik RadGrid using LINQ to SQL使用 LINQ to SQL 在 Telerik RadGrid 上进行 Web 控制 CRUD 操作
【发布时间】:2012-05-02 20:23:03
【问题描述】:

我有一个分层的 radGrid,用户单击详细信息表上的一行以在 Web 控件中编辑其数据。

如何使用 linq to sql 更新网格数据?

【问题讨论】:

    标签: asp.net linq-to-sql webforms telerik-grid radgrid


    【解决方案1】:

    我按照telerik提供的例子完成了这个任务,修改如下:

    protected void RadGridProductionOrders_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
            ProductionOrderDetail productionOrderDetail = new ProductionOrderDetail();
            ProductionDataContext db = new ProductionDataContext();
    
            productionOrderDetail = (from p in db.ProductionOrderDetails
                                     where p.orderNo == editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["orderNo"]
                                        && p.itemCode == editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["itemCode"]
                                     select p).Single();
    
            productionOrderDetail.qty = int.Parse((userControl.FindControl("TextBoxQty") as TextBox).Text);
    
            try
            {
                db.SubmitChanges();
            }
            catch(Exception ex)
            {
                Label lblError = new Label();
    
                lblError.Text = "Unable to update Production Order data. Reason: " + ex.Message;
                lblError.ForeColor = System.Drawing.Color.Red;
    
                RadGridProductionOrders.Controls.Add(lblError);
    
                e.Canceled = true;
            }
    }
    

    此代码完成后,网格将更新为新值。

    【讨论】:

      【解决方案2】:

      您也可以在 Telerik 的网站上查看演示(非常简单明了): http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/programaticlinqupdates/defaultcs.aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多