PDA

View Full Version : [CLOSED] dynamic ID call from code behind



FpNetWorth
Mar 07, 2013, 10:42 AM
dear support,
i am creating a container in my code behind inside a loop for i need many.
i am setting a dynamic ID for each container created inside the loop.
how can i call the dynamic ID to use the Hidden="true/false" property.
here's a snippet.


for (int i = 0; i < table.Rows.Count; i++)
{
Ext.Net.Container nbrFieldContainer = new Ext.Net.Container();
string nbrFieldContId = "nbrFieldContainer_" + i;
nbrFieldContainer.ID = nbrFieldContId;
nbrFieldContainer.Layout = "ColumnLayout";
Ext.Net.NumberField nbrField = new NumberField();
Ext.Net.Label lbl = new Ext.Net.Label();
nbrField.ID = "nbrField_" + i;
nbrField.Height = 30;
nbrField.Width = 100;
nbrField.MinValue = 1;
lbl.ID = "nbrId_" + i;
lbl.StyleSpec = "margin-left:10px";
lbl.Text = "Days";
nbrFieldContainer.Items.Add(nbrField);
nbrFieldContainer.Items.Add(lbl);
nbofdays.Component.Add(nbrFieldContainer);

if (table.Rows[i]["Value"].ToString() != "" && userSettingsTable.Rows[i]["value"].ToString() != "0")
{
//I NEED TO SHOW THE CONTAINER OF ID ("nbrFieldContainer_" + i )
}
else
{
//I NEED TO HIDE THE CONTAINER OF ID ("nbrFieldContainer_" + i )
}

}

please note that the conditions inside my conditional statements are correct. i just need to set an ID.Hidden to true or false.

thanks in advance
Michel

Daniil
Mar 07, 2013, 11:04 AM
Hi Michel,

Can't you do this?

nbrFieldContainer.Hidden = true/false;

Well, you don't need an ID if you have a control instance.

FpNetWorth
Mar 07, 2013, 2:06 PM
Hi Michel,

Can't you do this?

nbrFieldContainer.Hidden = true/false;

Well, you don't need an ID if you have a control instance.

dear Daniil,
if i do that, all of the nbrFieldContainer in all the rows in my gridpanel will be hidden/unhidden.
what i am doing exactly is creating a new Container in every row and giving it an ID depending on the counter inside the loop.
if i give the container a static ID, i will be able to refer it in my code behind.
however the ID is changing in every row.


best.
Michel

Daniil
Mar 07, 2013, 2:45 PM
But why the if statement is inside the loop statement if you don't need to set up the Hidden property for each statement?

Generally, Hidden is false by default. So, setting up it to false doesn't produce any effect (unless it happens in a DirectEvent).