+ Start a Discussion

Display selected picklist value in a apex:datalist.

Hello everyone,

I am trying trying to display the list of contacts associated with a certain account in a picklist. And then display the selected value on an apex datalist on the same visualforce page after clicking a button. Here is the relevant code (I left out all the unnecessary part):
public without sharing class AccountExt {

public String selectedConId{get;set;}

public AccountExt(ApexPages.StandardController Controller) {


public List<SelectOption> getContactNames() {
                  List<SelectOption> ConOptions= new List<SelectOption>();
                  ConOptions.add( new SelectOption('','--Select--'));
                  for( Contact Con : [select Id,name from Contact where Accountid =: '001r0000002atum' ] ) {
                          ConOptions.add(new SelectOption(Con.Id,Con.name)); 
                 return ConOptions;

Public void addSECCon(){
        SECCon = new SEC_Contract__c();
        SECCon.Vendor_Name__c = accnt.id;



And the VF code:
<apex:outputpanel id="addanother3">
                <apex:pageBlockSection columns="3" rendered="{!account.Previous_SEC_Contracts__c == 'Yes'}">                    
                     <apex:pageBlockSectionItem >
                         <apex:outputLabel >Contract Number</apex:outputLabel>
                         <apex:inputField value="{!SECCon.Contract_Number__c}"/>
                     <apex:pageBlockSectionItem >
                         <apex:outputLabel >Name</apex:outputLabel>
                         <apex:selectList value="{!selectedConId}" size="1">
                                               <apex:selectOptions value="{!ContactNames}" />
                     <apex:pageBlockSectionItem > 
                         <apex:commandButton value="Add" action="{!addSECCon}"  reRender="addanother3"/>
                <apex:pageBlockTable value="{!listSECCon}" var="sc" rendered="{!account.Previous_SEC_Contracts__c == 'Yes'}">
                <apex:column headerValue="Previous SEC Contract Number">
                <apex:outputField value="{!sc.Contract_Number__c}"/>
                <apex:column headerValue="Name">
                <apex:dataList value="{!selectedConId}" var="c">{!c}</apex:dataList>

I got the first part where I need to display all contacts in a picklist, but not able to show the names on the apex:datalist. Instead it is showing the record Ids. Can you show me how to display the names instead?
SonamSonam (Salesforce Developers) 
In the data list, you have displayed : selectedConId which I understand is the record ID  which is appearing in the datalist

<apex:dataList value="{!selectedConId}" var="c">{!c}</apex:dataList>

Can you share the code form the controller where you are setting the value of this property:selectedConId

Instead of ID, you should be fetching the contact name.