cancel
Showing results for 
Search instead for 
Did you mean: 

getting selected values in Drop Down

Former Member
0 Kudos

Hi,

im using dropdownbykey(DYNAMICALLY). So at the run time i wanted to get the selected element. In this i've created context dynamically

the code should as follows

if(selected value=INDIA)

{

do this;

so pls help me with it.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You have to access the value of the context attribute to which you have bound the "selectedKey" property.

Example: Attribute is named "country" and at root level:


String selectedCountry = wdContext.currentContextElement().getCountry();
/* or if attribute was created by code: */
String selectedCountry = (String) wdContext.currentContextElement().getAttributeValue("country");
if ( "INDIA".equals(selectedCountry) )
{
  /* INDIA is selected in drop-down list */
}

Armin

Former Member
0 Kudos

Hey I tried ur code but it's showing me the value which i've stored in the enumeration ie "select"

before u gave me the code i tried this code but it's also showing me the same value

if(fld.getName()=="country")

{

if(value=="Select")

{

value = "Country is not Selected";

//return;

}

}

Answers (1)

Answers (1)

former_member197348
Active Contributor
0 Kudos

Hi Amit,

I could not understand your requirement but change if condition

like this if the selected value is String

if(selected value.isEqualsIngonreCase(INDIA))

{

// do what you want

}

If you want to access the key of the DropDown dynamically, you can do like this

if(<DropDownInstance>.getSelectedKey().isEqualsIngonreCase(INDIA))

{

//

}

regards,

Siva

Former Member
0 Kudos

hey im not getting that how should i access that attribute value. i mean how do i come to know that the particular value is selected. The 1st element is Select. So if "Select" is selected then in the result i want to write "Country is not selected.

former_member197348
Active Contributor
0 Kudos

Hi Amit,

If you want to get the attribute value, you can get in two ways.

Using DropDown

1.Get the instance of DropDownByKey in wdDoModifyView()

like IWDDropDownByKey dbkey = (IWDDropDownByKey) view.getElement("ID_DROPDOWN");

2.Set the SelectedKey property

dbkey.getSelectedKey();

or

Using Context attribute

wdContext.current<dropdownnode>Element().get<DropDownAttribute>();

Do null check wherever necessary.

regards,

Siva