How to reference the new row in datagrid from codebehind

G

Guest

Hi

I use the Datagrid webcontrol on my web page, and I use the following client-side javascript to duplicate the current row to the datagrid. But when I loop through the data in datagrid from codebehind, it does not include this new row. Did I miss something? What should I do to reference this new row from codebehind? Thanks

JP Goo

var oTable = document.getElementById("myDataGrid")
var iCurRowIndex = window.event.srcElement.parentElement.parentElement.rowIndex
var oCurRow = oTable.rows(iCurRowIndex)
var oNewRow
var oNewCell

oNewRow = oTable.insertRow(iCurRowIndex + 1)
oNewRow.align = "Center"

for (var i = 0; i < oCurRow.cells.length; i++)
oNewCell = oNewRow.insertCell(-1)
oNewCell.innerHTML = oCurRow.cells(i).innerHTML
}
 
I

Igor Tandetnik

John Good said:
I use the Datagrid webcontrol on my web page, and I use the following
client-side javascript to duplicate the current row to the datagrid. But
when I loop through the data in datagrid from codebehind, it does not
include this new row. Did I miss something? What should I do to
reference this new row from codebehind? Thanks!

You can't. You see, on the server side you might have a DataGrid
control, but on the client you just have a bunch of assorted HTML tags
that just happen to look like a grid. Think not in terms of what the
things look like, but in terms of what information gets submitted to the
server when the user hits the button.

Remember - to the browser, an ASP.NET page is just a huge form with lots
of HTML in it. You can have a hidden field on this form, and have
client-side JavaScript set a value in this field, indicating that it has
just duplicated row X. On the server side, when you receive this value
in a post-back, you need to duplicate row X in your server-side DataGrid
control.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top