Replies
Hi Alan,
Our app is running in an architecture where in a wrapper control(.ascx) does all the WebDataGrid functionalities which is then leveraged by other user controls(.ascx). The wrapper and all other calling functionalities where designed around the old ultrawebgrid way of setting and retrieving objects.
Eg: DataBind was done on a wrapper method which was called from the page load of various module & setCellValue was called on certain button click events for edit features.
So based on your suggestion, if we need to change the datasource dynamically for checkbox values and then databind, it is more effort for migration considering the way our legacy app is designed using ultrawebgrid wrapper methods.
I was able to achieve the functionality of setCellValue wrapper method for checkbox scenarios using the suggestion of using client side javascripts . I dynamically created the below JavaScript method in server side logic and registered it into Client Side using Page.ClientScript.RegisterStartupScript and mapped it to the Initialize client side event. Not the straight forward way , but it is achieving what i was looking for.
function EditGrid_ctlDataTable_grdDataTable_Initialize_CheckBoxValueChange(grid, eventArgs) {
var checkState;
var cell;
cell = grid.get_rows().get_row(8).get_cell(4);
checkState = cell._getCheckState();
if(checkState == 1 || checkState == 0)
{
cell._setCheckState(0);
}
cell = grid.get_rows().get_row(10).get_cell(4);
checkState = cell._getCheckState();
if(checkState == 1 || checkState == 0)
{
cell._setCheckState(0);
}
cell = grid.get_rows().get_row(11).get_cell(4);
checkState = cell._getCheckState();
if(checkState == 1 || checkState == 0)
{
cell._setCheckState(0);
}
}
Svetla,
Which client side event method will this go into which mimic the ultrawebgrid server side logic for checkboxes-> grdDataTable.Rows(rowIndex).Cells(columnIndex).Value = true/false?
I am guessing it should go into some initialize events client side methods. If not can they be achieved on "EditingClientEvents.CellValueChanging"/"CellEditingClientEvents.EnteringEditMode" ?
Thanks,
Aravind
Hi Svetla,
I was able to perform 1 and 3 answers clean based upon your solution.
About 2:
In UltraWebGrid legacy library , we were able to set a check box Checked or UnChecked by setting the below property(value) with true/false in server side and then display grid to user. Then user clicks a button which performs a post back updating the database(based on the data shown in the grid) and then refreshing the datasource. However as per your response, i see it is not possible to do that in webdatagrid at server side, other than to modify the datasource value directly?
grdDataTable.Rows(rowIndex).Cells(columnIndex).Value = value
Is there a way to achieve this(Check/UnCheck of a CheckBox) by using Client Side JS events?(What i meant is a JS logic similar to the below which goes in some Client Side event which mimics the earlier functionality from ultrawebgrid for grdDataTable.Rows(rowIndex).Cells(columnIndex).Value =…)
var cell = eventArgs.getCell();
var rowIndex = cell.get_row().get_index();
var colIndex = cell.get_column().get_index();
if (rowIndex == 3 && colIndex == 2)
{
//Logic-> If there is a checkbox in this cell , Check the Check box in this cell
}
if(rowIndex == 2 && colIndex == 1)
{
// Logic-> If there is a checkbox in this cell , UnCheck the Check box in this cell
}
Thanks,
Aravind
Thanks Tacho, this solution is finally working! I am marking this as a verified answer since it solves the problem with add and edits. However i have run into another issue and since it is a new one, posted a new question in the forum.
Thanks Tacho,
A.) Add feature-> I have figured the logic for add functionality base on the below logic but i would like to get it confirmed if it is the right approach?:
Scenario: When Add feature is enabled, the newly added row shows up. Disable enter and tab on the added row, User types in the values in the added row and clicks a button. The On RowAdding event should be triggered:
Solution:
1. Ensure BatchUpdating="true" at EditingCore (Not sure why, but i can make it work only if this is true)
2. At the EditingClientEvents-RowAdding at EditingCore call a method. Logic of this method:
var toSave = false;
function cancelRowAdding(sender, e) {
if (!toSave) {
e.set_cancel(true);
}
toSave = false;
}
3. On the onClient click of the button call the below method:
function saveRow() {
toSave = true;
$find("<%= grdDataTable.ClientID%>")
.get_behaviors()
.get_editingCore()
.get_behaviors().get_rowAdding()._commitRow();
}
The above steps will ensure the RowAdding Server Event is called only upon button click.
B.) Edit Feature-> I am almost there (your solution has opened my eyes that not all features are available via Server Side) . But i have the following question and kindly confirm the below is the right approach?:
In the RowEditing_ExitedEditMode , Can you share the code on:
How to Find if Row Was actually Edited(that is at least 1 cell value in the row was changed from previous, done is clicked and then only set commit on the row edited, set isAlreadyRowEdited to true and then fire the On RowUpdating event)?
Scenario: When edit feature is enabled, the edit should be enabled at the first row user has selected and all other rows should have edit disabled. When user changes any cell in that row and he clicks done, then the On RowUpdating Event should be triggered. Then the grid should be non editable for any row.
Solution:
1. Add the below JS method for <SelectionClientEvents RowSelectionChanged="RowSelection_Changed" />
var selectedRowIndex = 0;
var isAlreadyRowEdited = false;
function RowSelection_Changed(webDataGrid, evntArgs) {
var grid = $find("<%= grdDataTable.ClientID%>");
var gridBehaviors = grid.get_behaviors();
var row = gridBehaviors.get_selection().get_selectedRows().getItem(0);
selectedRowIndex = row.get_index();
}
2. For the RowEditing_EnteringEditMode method:
function RowEditing_EnteringEditMode(sender, e) {
// Do not Allow Editing if Already a Row was edited previosly
if (isAlreadyRowEdited) {
e.set_cancel(true)
}
else {
var editingRow = e.getCells()[0].getCell().get_row();
// Allow Editing only for the selected row
if (editingRow.get_index() !== selectedRowIndex) {
e.set_cancel(true);
}
}
}
3. For the RowEditing_ExitedEditMode method:
function RowEditing_ExitedEditMode(sender, e) {
var grid = $find("<%= grdDataTable.ClientID%>");
// Find if Row Was Edited(that is atleast 1 cell value in the row was changed from previous, done is clicked and then only set commit the row edited and set isAlreadyRowEdited to true) How to?
grid.get_behaviors().get_editingCore().commit();
isAlreadyRowEdited = true;
}
Hi,
I did manage to iterate over the items collection in added row but all the newly added text is showing up empty in the value field. ViewState is enabled at the grid.
Dim row As GridRecord = Me.grdDataTable.Behaviors.EditingCore.Behaviors.RowAdding.Row
Dim i As Integer = 0
For i = 0 To row.Items.Count – 1
Dim key As String = row.Items(i).Column.Key
Dim value As String = row.Items(i).Text
Next
Thanks,
Aravind
Hi Tacho,
I have opened up a case-> CAS-194960-T5P2B0 and i have attached our working POC to the solution. Unfortunately point 1 and 2 dint gent resolved based on the solution provided. For point 3, can you provide the working code to convert Row to a c# DataTable? I did do a quick watch on the Row property, i do see the count but i cant get into the datavalues.
Thanks,
Aravind