Getting checked checkboxes values using apex

The below code is used to get the checked checkboxes values

Visualforce:

<apex:page standardController="Member__c" extensions="deleteBlog" >
<apex:form >

  <apex:pageblock title="Member" >
    <apex:pageblockButtons >
      <apex:commandButton value="Find" action="{!find}" reRender="SearchList"/>
    </apex:pageblockButtons>
    <apex:pageblocksection >
      <apex:inputfield value="{!Member__c.Name}"/>
    </apex:pageblocksection>
  </apex:pageblock>
 
  <apex:pageblock id="SearchList" title="Member List"  >
    <apex:pageBlocktable value="{!memList}" var="memLst" >
      <apex:column title="Select" > 
        <apex:inputCheckbox value="{!memLst.checked}" ></apex:inputcheckbox>
      </apex:column>
      <apex:column value="{!memLst.themem.Name}" title="Member Name" />
      <apex:column value="{!memLst.themem.E_Mail_Id__c}" title="E-Mail Id"/>
      <apex:column value="{!memLst.themem.Mobile_Number__c}" title="Mobile Number"/>
    </apex:pageBlocktable>   
    <apex:pageblockButtons >
      <apex:commandButton value="Delete" action="{!Del}" reRender="SearchList"/>
    </apex:pageblockButtons>      
  </apex:pageblock>
 
</apex:form> 
</apex:page>

Apex:

public class deleteBlog
{
    public boolean checked{get;set;}
    public List<Member__c> memTmpLst;
    public List<mem> memList {get;set;}
    public Member__c memb;
    String[] selectedNam = new String[]{};
    List<String> selectednames =new List<String>();
    public List<String> temp {get;set;}
    public List<Member__c> memDelList;  
    public Integer i; 
   
    public class mem
    {
      public Member__c themem {get; set;}
      public Boolean checked{get; set;}
      
      public mem(Member__c m,Boolean s)
      {
        themem = m;
        checked = s;
      }
    }

    public deleteBlog(ApexPages.StandardController controller)
    {
      this.memb = (Member__c)controller.getRecord();
    }
   
    public void find()
    {
      String nam = memb.Name;
      memList = new List<mem>();
      if(memList == null)
      {
        memList = new List<mem>();
      }  
      String sql = 'SELECT Name,Mobile_Number__c,E_Mail_Id__c FROM Member__c WHERE Name LIKE\'%'+nam+'%\'';
      memTmpLst = Database.query(sql);
      for(Member__c m:memTmpLst)
      {
        mem me = new mem(m,false);
        memList.add(me);
      }    
    }   
   
    public void del()
    {
      memDelList = new List<Member__c>();
      for(mem m:memList)
      {
        if(m.checked == true)
        {
          if(memDelList==null)
          {
            memDelList = new List<Member__c>();
          }
          memDelList.add(m.themem);     
    
        }             
      }
      Delete memDelList;
      find();
    }
}

Cheers!!!

No comments:

Post a Comment