如何在客户端对WebGrid进行数据的更新

作者:控件中国网   出处:控件中国网   2015-07-29 11:03:49   阅读:6

WebGrid支持客户端进行数据的添加、修改、删除和更新,下面就分别介绍如何使用JavaScript对WebGrid进行客户端数据处理。

1.客户端为表格插入行
function DoAdd()
{
    // retrieves WebGrid's object
    var grid = ISGetObject("WebGrid1");
    var newRow = grid.RootTable.NewRow(); // create new row object
    var cells = newRow.GetCells(); // get WebGridCell collection

    // populate new row object
    cells.GetNamedItem("CustomerID").SetText("MARTI", true);
    cells.GetNamedItem("CompanyName").SetText("Intersoft Solutions", true);
    cells.GetNamedItem("ContactName").SetText("Martin Anderson", true);
    cells.GetNamedItem("Country").SetText("Indonesia", true);
    newRow.Update(); // insert new record
}
2. 客户端更新表格数据
function DoUpdate()
{
    // retrieves WebGrid's object
    var grid = ISGetObject("WebGrid1");
    var selectedRow = grid.GetSelectedObject().ToRowObject(); // get selected row object
    var cells = selectedRow.GetCells();  // get WebGridCell collection

    // update the selected row's cells value
    cells.GetNamedItem("CustomerID").SetText("JAMES", true);
    cells.GetNamedItem("CompanyName").SetText("Brian Corporation", true);
    cells.GetNamedItem("ContactName").SetText("James Brian", true);
    cells.GetNamedItem("Country").SetText("Germany", true);
    selectedRow.Update(); // update the selected row object
}
3. 客户端删除表格行
function DeleteRow()
{
    // retrieves WebGrid's object
    var grid = ISGetObject("WebGrid1");
    var selectedObject = grid.GetSelectedObject();  // return object of type SelectedObject

    if (selectedObject != null)
    {
        var selectedRow = selectedObject.ToRowObject(); // return WebGridRow object
        selectedRow.Delete(); // delete the selected row
    }
    else
    {
        alert("Please select a row first.");
    }
}

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat