This is a migrated thread and some comments may be shown as answers.

Changing Radgrid value returns &nbsp

10 Answers 299 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peny
Top achievements
Rank 1
Peny asked on 19 Jul 2012, 07:41 AM
Hello ,

I have an issue when I change a cell value from java script.

My case is:

I have a Radgrid and a user can select a row.
When the user selects the row, I get the row key and allow him to add a new action, by opening a new Radwindow.
When the window closes, I return the id of the action added.

On closeEvent, I call a javascript function where the value returned goes to a cell at the initial grid (this cell has no value from DB).
The code I use to change the value is the following:

function refreshDataActions(oWnd, args) {
              
var arg = args.get_argument();
               
if (arg) {
                  
if (arg.actionId) {
                      
var HiddenField_contract_value = document.getElementById("HiddenField_contract").value;
                       
var grid = $find("<%=contractsGrid.ClientID %>");
                       
var MasterTable = grid.get_masterTableView();
                       
var rows = MasterTable.get_dataItems();
                      
for (var i = 0; i < rows.length; i++) {
                          
var row = rows[i];
                           
var activeCell = MasterTable.getCellByColumnUniqueName(row, "actionRESULT");
                           
var contractRow = row.getDataKeyValue("CONTR_ID");
                          
if (contractRow == HiddenField_contract_value) {
                               activeCell.innerHTML = arg.actionId;
                           }
                        }
                          $find(
"<%= RadAjaxManager1.ClientID %>").ajaxRequest("actionAdded");
                   }
                }
            }

Everything works until now. I can see the new value at the grid.

When the returned value is not null, I perform an Ajax request, and the I check the value at the cell if changed.
My problem is, that when I loop through the items of the grid, I get a "&nbsp" value.
The code I use to loop through the items is the following
 
For Each item In contractsGrid.Items           
      If item("actionRESULT").text <> "&nbsp" Then               
            counterActions = counterActions + 1          
      End If       
Next

Is there something I am missing here?

I would really appreciate your help!

Thank you in advance,
Peny

10 Answers, 1 is accepted

Sort by
0
Peny
Top achievements
Rank 1
answered on 19 Jul 2012, 12:32 PM
Anyone????
Please!!!!!!
0
Matt
Top achievements
Rank 1
answered on 22 Jul 2012, 07:27 PM
I've had the same issue, and after lots of debugging, I've gotten this far:  .innerHTML doesn't seem to change the value, but rather just the innerHTML of a cell in the radGrid.  However, why can't you just play with that instead of the value?
0
Peny
Top achievements
Rank 1
answered on 23 Jul 2012, 11:29 AM
Hello Matt,

thank you very much for your answer!

The solution that you suggest, seems right, but I  tried to do so, and I cannot get the cell inner Html from server side.

Do you know the exact code I should use?

Thanks in advance,
Peny
0
Peny
Top achievements
Rank 1
answered on 24 Jul 2012, 08:43 AM
Hello,

I managed to solve my problem by checking the cell's innerHtml from client-side.
The code I used is the following
                  function checkInserted() {
                           var grid = $find("<%=contractsGrid.ClientID %>");
                        var MasterTable = grid.get_masterTableView();
                        var rows = MasterTable.get_dataItems();
                        var counterAll = rows.length;
                        var counterWithAction=0;
                        for (var i = 0; i < rows.length; i++) {
                            var row = rows[i];
                            var activeCell = MasterTable.getCellByColumnUniqueName(row, "actionRESULT");
                            if (activeCell.innerHTML != " ") {
                                counterWithAction = counterWithAction + 1;
                            }
                        }
                        if (counterAll == counterWithAction) {
                            document.getElementById("Button_next").disabled = false;
                            document.getElementById("Button_close").disabled = false;
                                                                 }
            }

The problem now, is that the value in the cell disappears after the row selection.
I want to maintain the value inserted programmatically in the cell after the contractsGrid_SelectedIndexChanged event.

How could I achieve that????
0
Matt
Top achievements
Rank 1
answered on 24 Jul 2012, 09:53 AM
You're saying that after a postback, the values of the innerHTML for all the cells reverts back to what it was before the changes?  That makes sense.  After all, the changes that you're making are all client-side, and the postback will eliminate those. 

Without understanding your project completely, I'd say you're trying to do something like this:

1. From the server side, you're binding this radGrid. 
2. When they click on something in the radGrid, you're using javascript/jquery to open a new window, get some data, close the window, and input that data within the radGrid.
3. At some point, when the user presses a save button, you send them server side again, where you want to grab the data in the radGrid and save it.

Is this right?

If it is, you have two options.  But first, tell me if this right.
0
Peny
Top achievements
Rank 1
answered on 24 Jul 2012, 10:07 AM
I will comment on your post:

1. From the server side, you're binding this radGrid.   TRUE

2. When they click on something in the radGrid, you're using javascript/jquery to open a new window, get some data, close the window, and input that data within the radGrid. TRUE (the user selects a row at the grid, and I get the value of the row key)

3. At some point, when the user presses a save button, you send them server side again, where you want to grab the data in the radGrid and save it. Not actually. When the user selects another row, the radgrid fires a postback, and the inserted value gets lost. I don't want to save the value. I just want to keep those values after postback .

The logic behind this is the following:
  1. The user must perform an action, for every row in the radgrid.
  2. The action is performed by opening the window( I am not getting in a lot of details here.... there is no point).
  3. I get the id,description of the action performed on window.close . I get the row for witch the action performed, and I set the value at a specific cell with the action's description.
  4. I do this for all rows.

If the user performed an action for all rows, i enable the "next" button(so he can leave the page).

Is that more clear now??

Thank you soooo much for your help!!! :)

0
Matt
Top achievements
Rank 1
answered on 24 Jul 2012, 11:14 AM
Sorry to keep asking questions, but why do you do a postback when another row is selected?
0
Peny
Top achievements
Rank 1
answered on 24 Jul 2012, 11:18 AM
You are trying to help me.... !!!!

Actually, I don't want to postback on selected row changed.
I am trying to find a way to avoid that...
But so far I cannot, because I want to bind some other controls based on that selected row...

This is my other issue :http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-row-selection-rebinds-another-controls.aspx


0
Matt
Top achievements
Rank 1
answered on 24 Jul 2012, 11:28 AM
Okay, I'm slowly starting to get better picture here.  RadGridInstallments, Label1 , RadGrid5 when a row in contractsGrid is clicked. Ideally, you want to avoid a postback, but you have to rebind RadGridInstallments and RadGrid5 with new data, and so therefore a postback is necessary.

When you postback, from where do you get the new data for RadGridInstallments and RadGrid5?  Is there any way you can grab is client-side?
0
Peny
Top achievements
Rank 1
answered on 24 Jul 2012, 11:29 AM
I think I am getting closer....

I disabled the "EnablePostBackOnRowClick"
I created a function
function RowClick(sender, eventArgs) {
 document.getElementById("HiddenField_contract").value = eventArgs.getDataKeyValue("CONTR_ID");
$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("rowSelected");}
and at the I set at the contractsGrid Clientevents the following
<ClientEvents OnRowClick="RowClick" />
At server side I do
Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
        If e.Argument = "rowSelected" Then
            fetchContractDetails(HiddenField_contract.Value)
            RadGridInstallments.DataBind()
            updatePanelInstallments.Update()
            RadGrid5.DataBind()
            UpdatePanel3.Update()

.....

So far it seems that I avoided the postback.
The contractsGrid doesn't lose the changed value...

I will do some more testing and let you know...
Tags
Grid
Asked by
Peny
Top achievements
Rank 1
Answers by
Peny
Top achievements
Rank 1
Matt
Top achievements
Rank 1
Share this question
or