function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tiruchuri AdityanTiruchuri Adityan 

OnRowClick() event in Apex

Hi,

I am having a pageblocktable and by clicking on a particular row it should take a particular field value as input and should display the details of that particular field in another table.  Can you send me code in both VF and Apex.
AshwaniAshwani
This might help in make use of attribute:

<script>
var lastRow;
function highlight(elem){
    if(lastRow != undefined)
        lastRow.style.backgroundColor = 'white';

    elem.style.backgroundColor = 'yellow';
    lastRow = elem;
}
</script>

<apex:pageBlock >
<apex:pageBlockTable value="{!list1}" var="item" rules="rows" id="myTable1">
    <apex:column value="{!item.id}" />
    <apex:column value="{!item.name}"/>
    <apex:actionSupport event="onRowClick" reRender="" onsubmit="highlight(this);">
        <apex:param name="cId" value="{!item.id}" assignTo="{!myStringValue}"/>
    </apex:actionSupport>
</apex:pageBlockTable>    
</apex:pageBlock>


Tiruchuri AdityanTiruchuri Adityan
Thanks for immediate response. But that havent achieved.. When I click on a row in a table it should retrieve particular fields of a particular coloumn in below table. 

<apex:page controller="prac1">
    <apex:pageBlock title="Multiple Search and Split">
            <table cellpadding="3px" cellspacing="4px" >
                <tr height="20px">
                    <apex:form >
                    <td style="vertical-align:middle;">
                    Search by </td> <td style="vertical-align:middle;">
                 <apex:selectList size="1">
                <apex:selectOption itemValue="Serial" itemLabel="Serial Number"/>
                <apex:selectOption itemValue="Oppo" itemLabel="Opportunity"/>
                <apex:selectOption itemValue="EUC" itemLabel="End User Company"/>
            </apex:selectList>
                </td>
                <td style="vertical-align:middle;">
            <apex:inputTextarea style="overflow-y:scroll; resize:none; min-height:30px; max-height:30px; min-width:250px; max-width:250px" value="{!searchstring}"/> </td>   
            <td style="vertical-align:middle;">    <apex:commandButton value="Search" action="{!search}"/> </td>   
           <td style="vertical-align:middle;">    <apex:commandButton value="Split"/></td>   
           <td style="vertical-align:middle;">    <apex:commandButton value="Consolidate"/></td>   
           <td style="vertical-align:middle;">    <apex:commandButton value="Unconsolidate"/> </td>   
           <td style="vertical-align:middle;">    <apex:commandButton value="Export"/> </td>   
                    <td style="vertical-align:middle;">    <apex:commandButton value="Export Asset"/> </td>
                    </apex:form>
                </tr>
                </table>
         <apex:pageBlockTable value="{!acc}" var="a" cellpadding="10px" width="100%"> 
         <apex:column >
         <apex:facet name="header">Name</apex:facet>
         <apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Name} </apex:outputlink>
         </apex:column>
         <apex:column >
                <apex:facet name="header">Opportunity id</apex:facet>
                        {!a.id}
         </apex:column>
     <apex:column >
                 <apex:column >
                <apex:facet name="header">Amount</apex:facet>
                        {!a.amount}
         </apex:column>
       <apex:actionSupport event="onRowClick" reRender="" action="{!click}">
        <apex:param name="cId" value="{!a.Name}" assignTo="{!myStringValue}"/>
      </apex:actionSupport>
    </apex:pageBlockTable>    
       <apex:pageBlockTable id="sa" value="{!ass}" var="b" rendered="true">
            <apex:column value="{!b.asset1__c}"/>
              </apex:pageBlockTable>
           </apex:pageBlock>
</apex:page>

And the controller is 

public with sharing class prac1 { 
   public list <opportunity> acc {get;set;}
   public list <Asset> ass {get;set;}
   public string searchstring {get;set;}
   public string myStringValue {get;set;}

public prac1()
   { 
   } 
 
public void search()

     string searchquery='select name, Id, Amount, CloseDate, StageName from Opportunity where name like \''+searchstring+'%\' Limit 20'; 
     acc= Database.query(searchquery); 

public void click()
  {
   string squery='select name, asset1__c, asset2 from Asset__c where name like \''+myStringValue+'%\' Limit 20'; 
        ass= Database.query(squery);
  }  
}

And in this Opportunity is a standard object and Asset is a custom object..