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
Hello,
Your best option is to use the FromDataKey method or the index of the rows collection to find the row to update.
Please let me know if you have any questions.
Thanks,
Valerie
Thanks Valerie,
How do I code that? I've tried these with no luck...
grdDetail.Rows.FromDataKey(0) = sBusinessNamegrdDetail.Rows.FromDataKey("BusinessName") = sBusinessName
How does it know I want to set the "NEW" row BusinessName cell with the value of sBusinessName?
Can some one please help me with the server side code (C#) to set a cell value during the row added event.
I am glad you were able to resolve your issue. Please let me know if you have any other questions.
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 .......
Please let me know more information on how you are adding the row and what your requirements are so that I can be of further assistance.