cancel
Showing results for 
Search instead for 
Did you mean: 

Create Label dynamically and set text dynamically

Former Member
0 Kudos

Hi all,

I need to create labels dynamically in my view. The text for these labels should be set from data accessed from a sql table. My sql table contains two fields 'id' and 'name'.

Currently my sql database table has 5 records.I am able to print all these in the wdmodify view.

But how can I create the label for these 5 records and set its text with 'name' from the sql table?

for eg: label1.setText(<set with 'name' from database table>)

How will I do this dynamically?code would be helpfull

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

nikhil_bose
Active Contributor
0 Kudos

in WDModifyView() {


if(firstTime) {

IWDTransparentContainer container = (IWDTransparentContainer)view.getElement("RootUIElementContainer");
    IWDLabel label;
//recordset is your database return
    for(int i = 0; i<recordset.length;i++){
		
    	label = (IWDLabel)view.createElement(IWDLabel.class,new String("label"+i));
    	container.addChild(label);
    	label.setText(recordset.getID());// get ID from recordset
    }

nikhil

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi

Try this code


//@@begin wdDoModifyView
    
IWDTransparentContainer container = (IWDTransparentContainer)view.getElement( "RootUIElementContainer");	
IWDLabel label;
for( int i = 0; i < 10; i++)
{
	container.addChild( label = (IWDLabel)view.createElement( IWDLabel.class, "Label_" + i));
	label.setText( "Label " + i);
}
//@@end

to display the database value say id to the label, you can directly set the contextElement that you bind with the database field to the setText(). You can convert the type of it by using .toString() or Typecast to string Ex:

label.setText( (String)wdContext.currentContextElement().getID());

or

label.setText( wdContext.currentContextElement().getID().toString());

Regards

- Vinod

*

Former Member
0 Kudos

Hi

write the following code in the wdDoModifyView() method.

1)First get the Ref of the Transaparent container.

IWDTransparentContainer con=(IWDTransparentContainer)view.getElement("id of container");

IWDLabel label=(IWDLabel)view.createElement(IWDLabel.class,null);

label.setText("Text1");

con.addChild(label);

Regards

Hazrath