How to set cell value on client?

10 posts, 0 answers
  1. Rusty
    Rusty avatar
    3 posts
    Member since:
    Sep 2010

    Posted 23 Jan 2013 Link to this post

    Hello,
    I need to set some radgrid cell values client-side, via javascript.  Then at postback I need to access those values.  Currently I'm setting the cell's innerHTML property, which displays correctly in the grid.  However, at postback all the cell values revert to " ".  At postback, I am not re-binding the grid.  
    Thanks!
    -rusty

    Here's how I set values on the client-side:

    // For all selected rows, set the cell value.
    function rgSetSelectedRowValue(rg, columnName, val) {
        var table = rg.get_masterTableView();
        var selectedRows = table.get_selectedItems();
        for (var i = 0; i < selectedRows.length; i++) {
            var row = selectedRows[i];
            var cell = table.getCellByColumnUniqueName(row, columnName);
            cell.innerHTML = val;
        }
    }

    Here's how I access values server-side:

    // loop on grid rows
    foreach (GridDataItem item in RadGrid1.MasterTableView.Items) {
    string foo = item["ReplacementID"].Text;
    string bar = item["comment"].Text;
    ...
    }




  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 23 Jan 2013 Link to this post

    Hello,

    function AccessOnclient() { 
                    var grid = $find("<%= RadGrid1.ClientID %>"); 
                    if (grid) { 
                        var MasterTable = grid.get_masterTableView(); 
                        var Rows = MasterTable.get_dataItems(); 
                        for (var i = 0; i < Rows.length; i++) { 
                            var row = Rows[i]; 
                            // Method1 
                            var getCellText_1 = row.get_element().cells[0].innerHTML; 
                            // Method2 
                            var getCellText_2 = row.get_cell("ReplacementID").innerHTML; 
                            // Method3 
                            var getCellText_2 = row.get_cell("ReplacementID").getElementsByTagName("span")[0].innerHTML; //this code also work for Checkboxcolunm, hyperlinkcolumn...etc 
                        
                    
                   
                }

    For more info please check below link
    http://jayeshgoyani.blogspot.in/2012/07/access-radgrid-on-client.html

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rusty
    Rusty avatar
    3 posts
    Member since:
    Sep 2010

    Posted 23 Jan 2013 Link to this post

    Thanks Jayesh, but my problem lies with SET values, not GET values.  I want to SET a grid cell value on the client, and then have that value available on the server at postback.  When I set innerHTML, the value is lost at postback.
    -r
     
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Jan 2013 Link to this post

    Hi,

    You cannot get the values that are changed in the client side from server side because of postback. One suggestion is that you can set the value to a hiddenfield as the cell value in client side and access it in server side as shown below.
    JS:
    function rgSetSelectedRowValue(rg, columnName, val) {
        var table = rg.get_masterTableView();
        var selectedRows = table.get_selectedItems();
        for (var i = 0; i < selectedRows.length; i++) {
            var row = selectedRows[i];
            var cell = table.getCellByColumnUniqueName(row, columnName);
            cell.innerHTML = val;
           var hidden = document.getElementById("HiddenField1");
                hidden.value = cell.innerHTML;
        }
    }
    C#:
    protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
            string cellvalue= HiddenField1.Value;
            }
    }

    Thanks,
    Shinu
  6. Rusty
    Rusty avatar
    3 posts
    Member since:
    Sep 2010

    Posted 25 Jan 2013 Link to this post

    Thanks for your reply, Shinu.  I am aware of the possibility of using hidden fields, however I am storing a LOT of stuff in the grid cells, so the hidden field method is rather messy.  

    In the past, I've used another 3rd-party grid that supported "unbound columns", which could be populated on the client, then accessed server-side after a postback.  It looks like this is not possible with RadGrids.  

    My current solution is to use the grid to store my data, and then handle it all client-side without doing a postback.  Took a bit of refactoring but it's working now.

    -rd
  7. Abitar
    Abitar avatar
    22 posts
    Member since:
    May 2015

    Posted 25 Aug 2015 Link to this post

    Hello,

    How can I get the DataKeyValue of the row when I click on a button inside the RadGrid ?

     

  8. Abitar
    Abitar avatar
    22 posts
    Member since:
    May 2015

    Posted 25 Aug 2015 in reply to Abitar Link to this post

    using javascript
  9. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 25 Aug 2015 in reply to Abitar Link to this post

    Hello,

    Please look into this.

    Thanks, Jayesh Goyani

  10. Abitar
    Abitar avatar
    22 posts
    Member since:
    May 2015

    Posted 26 Aug 2015 in reply to Jayesh Goyani Link to this post

    Thank you Jayesh .
  11. satish
    satish avatar
    1 posts
    Member since:
    Aug 2016

    Posted 04 Aug Link to this post

    Hi Rusty,

    I am also in the same boat. I have switched from other 3rd party control that supported "unbound columns", which could be populated on the client, then accessed server-side after a postback.  I am trying to set the RadGrid cell values from client side and accessing the same from server side . But after postback value disappears.

    My client side code :

     function GetSelectedItem(arg) {
                    if (arg!=null | arg!=undefined) 
                    {
                        var grid = $find("<%=RadGridRoyaltyMapping.ClientID %>");
                        var MasterTable = grid.get_masterTableView();
                        var selectedRows = MasterTable.get_selectedItems();
                        for (var i = 0; i < selectedRows.length; i++) {
                            var row = selectedRows[i];
                            var sPart = arg.split('|');   
                            var cell = MasterTable.getCellByColumnUniqueName(row, "ID_ITEM");
                            cell.innerHTML = sPart[0];
                            var cell2 = MasterTable.getCellByColumnUniqueName(row, "EXPECTED_VALUE");
                            cell2.innerHTML = sPart[1];

                        }
                    }
                }

     

     

    Server side code  :

     protected void btnApply_Click(object sender, EventArgs e)
            {
                foreach (GridDataItem item in RadGridRoyaltyMapping.Items)
                {
                    string idItem = item["ID_ITEM"].Text.ToString();
                    string idExpectedValue = item["EXPECTED_VALUE"].Text.ToString();
                }
            }

    If you found a solution, Please share it.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017