Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
115
How to Set a cell Value in a New Row
posted

Hi,

I cannot figure out how to set the value of a specific cell in a new row to the value of a variable.  Any ideas?  Thanks!  Here's the code I have:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Protected Sub btnAddParent_Click(ByVal sender As System.Object, ByVal e As  System.Web.UI.ImageClickEventArgs)

 

 

Dim BusinessName As String

 

 

'Set the variable to the value of the first row, first column:
BusinessName = grdDetail.DisplayLayout.Rows(0).Cells(1).Value

hfCellToFocus.Value = 1

grdDetail.Rows.FromKey(0).Cells(1).Text = BusinessName 'THIS DOESN'T WORK, I get a message that says "Object reference not set to an instance of an object".

 

 

End Sub

Parents
No Data
Reply
  • 385
    posted

     

    If you're using the grid's RowAdding behavior, you can do this:

    In the ASPX, set a client event for AddNewRowClientEvents.EnteringEditMode event:

     <AddNewRowClientEvents EnteringEditMode="Grid_RowAdding_EnteringEditMode" />

    then in the BLOCKED SCRIPT

          function Grid_RowAdding_EnteringEditMode(sender, eventArgs) {
                ///<summary>
                ///
                ///</summary>
                ///<param name="sender" type="Infragistics.Web.UI.WebDataGrid"></param>
                ///<param name="eventArgs" type="Infragistics.Web.UI.EditModeEventArgs"></param>

                var NEW_ROW_STATE = 0;
                var INITALIZED_ROW_STATE = 1;

                // index to a hidden grid row that tracks grid row state
                var STATE_ROW_INDEX = 0;
                var row = eventArgs.getCell().get_row();

                var cell = row.get_cell(STATE_ROW_INDEX);

                if (cell.get_value() == NEW_ROW_STATE) {

                    // mark the row to indicate it has been initialized
                    cell.set_value(INITALIZED_ROW_STATE);
                   
                    // initalize the row text/values
                    row.get_cell(4).set_text('default value 4');
                    row.get_cell(5).set_text('default value 5');
                    row.get_cell(6).set_value(34);
                    // etc.
                   
                }

            }

    ------End JavaScript-----

    In my case, I only populate the columns with static values. You will have to make some changes to this code to populate with dynamic values. Hope it helps.

Children
No Data