PDA

View Full Version : HTML table Row ID


dpkbahuguna
04-17-2008, 08:56 PM
hi All,
I m new to c#.I m using a HTML table in web browser control and wants to get the rowid of the clicked row in HTML table.bt dont have any idea how to get.
IS there any method for getting the row id of the clicked cell.
Please help me in solving the problem thanx in advance.

mjlorbet
04-18-2008, 12:36 AM
<script type="text/javascript">
function getRow(obj){
var prnt = obj.parentElement;
while(prnt.tagName != 'tr')
prnt = prnt.parentElement;
return prnt.id;
}
</script>


to be used as

<td onclick = "alert(getRow(this));">...</td>


also, you could put this event handler on any element nested within a cell and it would search up the tag heirarchy to find the element with the given tag name (in this case tr for table row). if you need to send this information back to the server, implement an onchange action to a hidden field (server side) and use <td onclick = "document.getElementById('myField').value = getRow(this);">...</td> to trigger the event. if the event doesn't fire automatically, call the __dopostback function with the appropriate inputs (should be able to see how to do it as the hidden field will actually have the exact call listed in its event handlers).

dpkbahuguna
05-07-2008, 05:00 AM
function RetFun(Obj) // here in obj variable I’m passing the Array.
function RetFun(Obj)
{
if(Inc == 'NO')
{
var cnt = document.getElementById('Table_JobOrderDet').rows.length;
for(i1=0;i1<cnt;i1++)
document.getElementById('Table_JobOrderDet').deleteRow(0);
}
Inc = 'NO';



DataVar = Obj.value;
var TotRows = new Array();
alert('one');
alert(Obj.value);
alert('Two');
TotRows = DataVar.split("~~~");
alert('TotRows.length');
var DetTab = document.getElementById('Table_JobOrderDet').insertRow(0);
var ColJobNo = DetTab.insertCell(0);
var ColMsg= DetTab.insertCell(1);
var ColMsgDt = DetTab.insertCell(2);
var ColToName = DetTab.insertCell(3);
var ColFrmName = DetTab.insertCell(4);
var ColSno = DetTab.insertCell(5);
ColJobNo.innerHTML = "JOB NO.";
ColMsg.innerHTML = "MESSAGE";
ColMsgDt.innerHTML = "DATE";
ColToName.innerHTML = "FROM";
ColFrmName.innerHTML = "TO";
ColSno.innerHTML = "SNO";

for(i=0; i<TotRows.length; i++)
{

var DetTab = document.getElementById('Table_JobOrderDet').insertRow(i+1);
var ColJobNo = DetTab.insertCell(0);
var ColMsg= DetTab.insertCell(1);
var ColMsgDt = DetTab.insertCell(2);
var ColToName = DetTab.insertCell(3);
var ColFrmName = DetTab.insertCell(4);
var ColSno = DetTab.insertCell(5);

var cols = new Array();
cols = TotRows[i].split("^^^");
for(j=0; j<cols.length; j++)
{
if(j == 0)
ColJobNo.innerHTML = cols[j];
else if(j == 1)
ColMsg.innerHTML = cols[j];
else if(j == 2)
ColMsgDt.innerHTML = cols[j];
else if(j == 3)
ColToName.innerHTML = cols[j];
else if(j == 4)
ColFrmName.innerHTML = cols[j];
else if(j == 5)
ColSno.innerHTML = cols[j];
}
}
}

************************************************************************

mjlorbet
05-07-2008, 05:08 AM
2 things...
1) Always put your code inside [ CODE] [ /CODE] tags, they're the # in the editor
2) What is it you're asking for? there's nothing but code on your post

dpkbahuguna
05-11-2008, 05:41 AM
hello,

I've to use Click Event in my code, how can I do this, because I m not using here <TR> or <TD> tags so I m confused so pls tell me if i need to use event then how will i put them...

Thanks!!