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:
'Set the variable to the value of the first row, first column:BusinessName = grdDetail.DisplayLayout.Rows(0).Cells(1).ValuehfCellToFocus.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
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.
Can some one please help me with the server side code (C#) to set a cell value during the row added event.
Hello,
I am glad you were able to resolve your issue. Please let me know if you have any other questions.
Thanks,
Valerie
I figured it out. Instead of doing anything with Javascript, I got it to work on the server side by doing this...
sBusinessName = grdDetail.DisplayLayout.Rows(0).Cells(1).ValuesACFieldName = grdDetail.DisplayLayout.Rows(0).Cells(2).Value
'Add a new rowgrdDetail.Rows.Add()
'Get the last row that was just addedDim rowAdded As UltraGridRow = grdDetail.Rows(grdDetail.Rows.Count - 1)
'Set valuesrowAdded.Cells(1).Value = sBusinessNamerowAdded.Cells(1).Value = sACFieldNamerowAdded.Activate()
Valerie,
I have a button that calls a sub function called btnAddParent_Click function (see on my original post). That function then calls a common Javascript function below:
function GridAfterPartialPostback() {
if (aspnetForm.ctl00_cphMaster_hfError.value == '') {
var newCell; var row; var cell;
if (aspnetForm.ctl00_cphMaster_hfLastKey.value == 'InsertRow') { row = igtbl_addNew(aspnetForm.ctl00_cphMaster_grdDetail.id, 0); CurrentRowName = row.Id; row.scrollToView(); // the page must pass the cell to be focused. if (aspnetForm.ctl00_cphMaster_hfCellToFocus.value != null) { newCell = row.getCell(aspnetForm.ctl00_cphMaster_hfCellToFocus.value) newCell.beginEdit(); } } else if .......