Setting both the Text and Value properties of Items in the SalesLogix ComboBox control

SalesLogix web has a “ComboBox” control which is actually rendered on the deployed page as an ASP ListBox control.  In the Application Architect you can see the control has two properties for Value and Text.  The value

ComboBox Properties

One would assume SalesLogix would have a built in property exposed to allow you to add items to the ComboBox and to set the Text and Value portions of said items, and they do, sort of.  If you go to a code editor in the Application Architect and start looking at the attributes and methods exposed for the ComboBox you will see an Items collection with an Add method.  Looks like we have it.

CodeHelp

As the code help shows the add method takes two parameters on for the text string and one for the value string. The only problem with this is if you do so, something like:

 

cboProblem.Items.Add(“Some text”,”ID123”);

You will get an error when you visit the page on the web site along the lines of:

 

A smart part associated with this page has failed to load: c:InetpubwwwrootsiteSLXClientSmartPartsTicketTicketCall.ascx(124): error CS1501: No overload for method ‘Add’ takes ‘2’ arguments

If you pass in instead just:

cboProblem.Items.Add(“some text”);

 This will work, however both the text and value properties of the list item will be “Some Text”.  Not good if you need to know a specific ID value of a list item chosen.

 So what gives?  Well it turns out what you actually need to pass into the Add method is a ListItem.  The list item can then have two values, one for text and one for value.  So the proper format of the add command would be:

 

cboProblem.Items.Add( new System.Web.UI.WebControls.ListItem(“Some text”,”ID123”));

Now that you have populated the list with your various entries and defined the text and value portions of the items you can retrieve them like so:

 

 

//get selected item’s  value
string val = cboProblem.Items[cboProblem.SelectedIndex].Value
//get selected item’s text
string disp = cboProblem.Items[cboProblem.SelectedIndex].Text

ABOUT THE AUTHOR

Kris Halsrud

Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

1 Comment

  1. Kris,
    How do you do this using a datasource in version 8.3 SPK10? Is it possible?

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!