I am using the following code to get data from the row of datagrid (that has two columns name and id) using button inserted in row that:

global $dal;
$record=$button ->getCurrentRecord();
$adddata=$ ->Table('transadd');
$adddata->id=$result["ID"];
$adddata->Add();

In case there is repetition in name column , I am getting id of the first entry of the name even after clicking on the entry for the second id of same name.
Can someone help me with this???