示例#1
0
 protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
 {
     //Instantiate the context.
     using (NorthwindLinqToSqlDataContext context = new NorthwindLinqToSqlDataContext())
     {
         //Set the maximum amount of items the Grid will display.
         RadGrid1.VirtualItemCount = context.Orders.Count();
         //Query the model for the items for the current page.
         var ordersToBind = (from order in context.Orders
                             select order).Skip(RadGrid1.PageSize * RadGrid1.CurrentPageIndex).Take(RadGrid1.PageSize);
         //Set the datasource to the Grid instance.
         RadGrid1.DataSource = ordersToBind;
     }
 }
示例#2
0
    protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;

        //Instantiate the context.
        using (NorthwindLinqToSqlDataContext context = new NorthwindLinqToSqlDataContext())
        {
            //Get the primary key value using the DataKeyValue.
            int orderID = int.Parse(item.OwnerTableView.DataKeyValues[item.ItemIndex][RadGrid1.MasterTableView.DataKeyNames[0]].ToString());
            //Query the model for the element that should be updated.
            Order orderToUpdate = (from order in context.Orders
                                   where order.OrderID == orderID
                                   select order).FirstOrDefault();
            //Update the element.
            item.UpdateValues(orderToUpdate);
            //Submit the changes back to the context.
            context.SubmitChanges();
        }
    }
示例#3
0
    protected void RadGrid1_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;

        //Instantiate the context.
        using (NorthwindLinqToSqlDataContext context = new NorthwindLinqToSqlDataContext())
        {
            //Get the primary key value using the DataKeyValue.
            int lastOrderID = context.Orders.ToList().Last().OrderID;
            //Create the empty element that should be inserted.
            Order orderToAdd = new Order();
            //Apply the vlaues from the editor controls.
            item.UpdateValues(orderToAdd);
            //Increment the PK field.
            orderToAdd.OrderID = ++lastOrderID;
            //Add the element.
            context.Orders.InsertOnSubmit(orderToAdd);
            //Submit the changes back to the context.
            context.SubmitChanges();
        }
    }