DataGrid row ID

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I need to give each row an ID in a DataGrid as I need to retrive it through
JavaScript using the row ID rather than the index.

Is this possible at all?

Thanks all,

Jon
 
The table rows rendered by the datagrid do not have ID values. If you have to
assign ids to the rows you may use Javascript:

var tbl = document.getElementById("datagrid1");
//this loop would assign ids to the rows (including the header row)
for (var i=0;i<tbl.rows.length;i++)
{
tbl.rows.id="row" + i;
}
//the following line is a test to refer to a row by its id
alert(document.getElementById("row1").outerHTML);
 
Hello Phillip,

I've managed tio do this server side within the ItemDataBound event.
Basically use do the following:

e.Item.Attributes.Add("ID", [name]);

e.Item is the row.

Thanks,

Jon

Phillip Williams said:
The table rows rendered by the datagrid do not have ID values. If you have to
assign ids to the rows you may use Javascript:

var tbl = document.getElementById("datagrid1");
//this loop would assign ids to the rows (including the header row)
for (var i=0;i<tbl.rows.length;i++)
{
tbl.rows.id="row" + i;
}
//the following line is a test to refer to a row by its id
alert(document.getElementById("row1").outerHTML);

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Jon said:
Hello,

I need to give each row an ID in a DataGrid as I need to retrive it through
JavaScript using the row ID rather than the index.

Is this possible at all?

Thanks all,

Jon
 

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

Back
Top