+ Start a Discussion
Hari nadh babu Eluru 7Hari nadh babu Eluru 7 

starts with s in visual force

In search box if user enter a letter 's' then bring students name starts with s. In visualforce
Best Answer chosen by Hari nadh babu Eluru 7
Suraj Tripathi 47Suraj Tripathi 47
Hi Hari,
Here is the code:
Please try:

Vf Page:
<apex:page controller="Searchstudent">
    <apex:form >
        <apex:pageblock title="Search student Details Here">
            <apex:inputText value="{!key}"/>
            <apex:commandButton value="Search" action="{!search_now}"/>
            <apex:pageBlockTable value="{!stu}" var="c">
                <apex:column value="{!c.Name}"/>
                
            </apex:pageBlockTable>
        </apex:pageblock>        
    </apex:form>
</apex:page>

Apex class:
public class Searchstudent{
    
    public List<Student> stu{get;set;}
    public String key {get;set;}
    
    public PageReference search_now(){
        stu= [SELECT Id,Name FROM StudentWHERE Name like :(key+'%')];
        return null;
    }
}

Thanks.

 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Hari,

Do the user need to onclick search button in this scenerio?

Thanks,
 
Hari nadh babu Eluru 7Hari nadh babu Eluru 7
Yes sir user need onclick search button
Suraj Tripathi 47Suraj Tripathi 47
Hi Hari,
Here is the code:
Please try:

Vf Page:
<apex:page controller="Searchstudent">
    <apex:form >
        <apex:pageblock title="Search student Details Here">
            <apex:inputText value="{!key}"/>
            <apex:commandButton value="Search" action="{!search_now}"/>
            <apex:pageBlockTable value="{!stu}" var="c">
                <apex:column value="{!c.Name}"/>
                
            </apex:pageBlockTable>
        </apex:pageblock>        
    </apex:form>
</apex:page>

Apex class:
public class Searchstudent{
    
    public List<Student> stu{get;set;}
    public String key {get;set;}
    
    public PageReference search_now(){
        stu= [SELECT Id,Name FROM StudentWHERE Name like :(key+'%')];
        return null;
    }
}

Thanks.

 
This was selected as the best answer