In WebCombo, you can manipulate data such as adding, deleting and updating from
client-side.
This topic will show you how to add item, delete row and perform batch update
in unbound WebCombo.
To add item in unbound WebCombo from client side
- Drag HTML Button to the page.
- Add the following function in client-side to add the item:
function AddItem()
{
var wc = ISGetObject("WebCombo1");
var rows = wc.GetRows(); // get the WebCombo4's rows for addition
var newRow = wc.NewRow("NEWCUST2"); // instantiate new row with NEWCUST as the KeyValue, containing cells with empty value
var cells = newRow.GetCells(); // get the cells of the new row for value assignment
// addition
cells.GetNamedItem("ContactName").Text = "New Customer"; // write codes in the same way as in server-side object model, with similar object hierarchy.
cells.GetNamedItem("Address").Text = "New Address"; // assign value to Address Cell
cells.GetNamedItem("CustomerID").Text = "NEWCUST";
rows.Add(newRow); //add the newRow to the rows collection
// update all changes now
wc.UpdateUI();
}
|
- Next, add onclick ="AddItem()" on the HTML Button's tag like following:
<input id="Button1" type="button" value="Add Item" onclick="Add Item()"
/>
- Run the project.
To delete a row in unbound WebCombo
- Go to HTML view and add the following code:
function DeleteRow()
{
var WebCombo1 = ISGetObject("WebCombo1");
var rows = WebCombo1.GetRows();
rows.Remove(rows[0], true); //remove row 0 from Rows collection, 2nd parameter must always be set to true
WebCombo1.UpdateUI();
alert("Row 0 removed!");
}
|
- Invoke DeleteRow() function by adding the following code:
<input id="Button1" type="button" value="Delete Row" onclick="DeleteRow()"
/>
To perform batch update in unbound WebCombo
- Set WebCombo to unbound mode.
- Go to HTML view and add the following code:
function BatchUpdate()
{
var WebCombo1 = ISGetObject("WebCombo1");
var firstRow= WebCombo1.GetRows()[0]; // get the WebCombo1's rows
var firstCell = firstRow.GetCells()[0];
firstCell.Text = "Changed Text"; // modify the text
firstRow.SetChanged();
WebCombo1.UpdateUI();
alert("Batch Update done!");
}
|
- Invoke BatchUpdate() function by adding the following code:
<input id="Button1" type="button" value="Update" onclick="BatchUpdate()"
/>