+ Start a Discussion
nagalakshminagalakshmi 

Moving the values from up and down in vf page select options

Hi,

 

I am displaying the name field of account object in vf page select options. Now my requirement is move the values up and down when we click on the up and down command buttons. Any one please help me.

 

Thanks

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet and also upload the images in static resource.

 

==============Class==============

 

public class TestUpDown

{

    public string Name{get;set;}

    public List<SelectOption> slctAccount{get;set;}

    public integer i{get;set;}

    public TestUpDown()

    {

        i=0;

        slctAccount=new List<SelectOption>();

        for(Account acc:[select name from account])

        {

            slctAccount.add(new SelectOption(acc.Name,acc.Name));

 

        }

    }

     public PageReference MoveUp()

     {

         system.debug('@@@@@@Up');

        if(i > 0)

        {

            i = i-1;

            Name =slctAccount[i].getlabel();

        }

        return null;

    }

 

    public PageReference MoveDown()

    {

         system.debug('@@@@@@Down');

        if(i < slctAccount.size()-1)

        {

            i = i + 1;

            Name =slctAccount[i].getlabel();

            system.debug('@@@@@@Down'+Name );

        }

        return null;

    }

  

}

 

 

 

================VF Page==================

 

 

<apex:page controller="TestUpDown">

   <apex:form >

  <apex:outputPanel id="pnl" >

   <table>

       <tr>

           <td style="vertical-align:middle;">

              

               <apex:selectList value="{!Name}" size="1" >

                   <apex:selectOptions value="{!slctAccount}" ></apex:selectOptions>

               </apex:selectList>

            

           </td>

           <td style="vertical-align:top">

                <apex:panelGroup >

                    <br/>

                    <apex:image value="{!$Resource.Up}" Id="imageSelect" >

                        <apex:actionSupport event="onclick" action="{!MoveUp}" reRender="pnl" />

                    </apex:image>

                    <br/><br/>

                    <apex:image value="{!$Resource.Down}" Id="imageSelect1">

                        <apex:actionSupport event="onclick" action="{!moveDown}" reRender="pnl"/>

                    </apex:image>

                </apex:panelGroup>

            </td>

            </tr>

       </table>

 </apex:outputPanel>

 

   </apex:form>

</apex:page>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

nagalakshminagalakshmi

Hi,

 

Thanks for your reply. But it does not moves the values up and down. Please help me out

 

Thanks

kiranmutturukiranmutturu

to implement moving the values from up and down use jquery or javascript...i.e client side...