2012-02-10 56 views

回答

3

使用下列標準,

@(Html.Telerik().Grid<PackageDetails>() 
    .Name("gvPackage") 
    .DataKeys(keys => keys.Add(k => k.PKG_CODE)) 
    .Columns(column => 
    { 
     column.Bound(c => c.PKG_NAME).Title("Description").Width(200); 
     column.Bound(c => c.MESG_UNIT).Title("Measuring Unit").Width(100); 
     column.Bound(c => c.STD_QNT).Title("Quantity").Width(100); 
     column.Bound(c => c.MODEL).Title("Model").Width(100); 

     column.Bound(c => c.COMP_CODE).ClientTemplate("<input type='text' id='txtSerial<#=COMP_CODE#>' value='<#=PKG_NAME#>' />").Title("Serial Number"); 

     column.Bound(c => c.COMP_DESC).Title("Model").Width(100); 
            }) 
     .DataBinding(dbBindings => dbBindings.Ajax().Select("_PackageDetailsLoad", "SalesDept")) 

控制器代碼

[GridAction] 
     public ActionResult _PackageDetailsLoad(string programID, string projectID, string packageID) 
     { 
      objLoginHelper = (LoginHelper)Session["LogInInformation"]; 

      return View(new GridModel<PackageDetails> 
      { 
       Data = salesDal.ReadPackageDetails(programID, projectID, packageID) 
      }); 
     } 

在JavaScript中使用下面的代碼

$('#ddlProgram').change(function() {   
    LoadPackageAndBindGrid(); 
}); 

function LoadPackageAndBindGrid() { 

      var params = { 
       programID: $('#ddlProgram').val(), 
       projectID: $('#ddlProject').val(), 
       packageID: $('#ddlPackage').val() 
      }; 

      var grid = $('#gvPackage').data('tGrid'); 
      grid.dataSource._data = [];    

      // Reload The Package Details 
      grid.ajaxRequest(params); 
     } 
0

您可以執行您的插入代碼後,通過從控制器返回GridModel重新綁定網格:

[AcceptVerbs(HttpVerbs.Post)] 
[GridAction] 
public ActionResult _ItemInsert(int id, MyObject obj) 
{ 
    //Rebind the grid by sending the GridModel back 
    return View(new GridModel(myData)); // where myData is your grid data 
} 

不要忘了[GridAction]來裝飾你的控制器。

這是假定您的網格有一個ajax數據綁定聲明如下:

dataBinding.Ajax() 
.Insert("_ItemInsert", "Item" }) 
+0

我的模型綁定到下拉列表( – user571874 2012-02-10 10:57:58

0

在完成你的行動,你可以撥打:。 的jQuery( 「#gvPackage」)的數據( 「T形柵格」)ajaxRequest()

相關問題