Dynamic controls losing values

R

Raj

Hi there,

I am trying to get this work but I can't figure a solution. I have a
table on a web page (.aspx) and creating the table contents
dynamically. I have two cells for each row of table. First cell is a
label field, and second is a radiobuttonlist. Table looks some thing
like

Your favorite color? *)Red *)Blue *)Green
Age? *)20 *)30 *)40

Here comes the problem. In the submit button, I am trying to read the
selection as follows:

RadioButtonList rbl;
TableCell tc;
string sText;
int nTotal = tblStats.Rows.Count;
for (int i = 0; i < nTotal; i++)
{
tc = tblStats.Rows.Cells[1];
rbl = (RadioButtonList)tc.Controls[0];
sText = rbl.SelectedItem.Value;
}
The above code will always return the first selection (In the above
example: Red, 20 etc) Even if you select Blue, 40 etc. Actually that's
what the default selections were when page loads.
I have googled it but couldn't find what I was looking for. I will
truly appreciate your input.

Thank you,

Raj
 
R

Raj

Eliyahu,

I am doing that. It is just that it is not able to read the values
back. To keep it simple, I am not changing selections either. I just
want the same values that were loaded. Somehow it can't read. It will
always give the first item in radiobuttonlist even though it is not
selected.

Thanks,

Raj

Eliyahu said:
You have to re-create dynamically created controls on every postback.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Raj said:
Hi there,

I am trying to get this work but I can't figure a solution. I have a
table on a web page (.aspx) and creating the table contents
dynamically. I have two cells for each row of table. First cell is a
label field, and second is a radiobuttonlist. Table looks some thing
like

Your favorite color? *)Red *)Blue *)Green
Age? *)20 *)30 *)40

Here comes the problem. In the submit button, I am trying to read the
selection as follows:

RadioButtonList rbl;
TableCell tc;
string sText;
int nTotal = tblStats.Rows.Count;
for (int i = 0; i < nTotal; i++)
{
tc = tblStats.Rows.Cells[1];
rbl = (RadioButtonList)tc.Controls[0];
sText = rbl.SelectedItem.Value;
}
The above code will always return the first selection (In the above
example: Red, 20 etc) Even if you select Blue, 40 etc. Actually that's
what the default selections were when page loads.
I have googled it but couldn't find what I was looking for. I will
truly appreciate your input.

Thank you,

Raj
 
R

Raj

I figured why that was happening but I still can't explain why.
Anyways, I was populating RadioButtonList with values from a global
file and that was causing it. Now I am reading the value into a local
variable and using it and every thing works.

Thanks for your time,

Raj
Eliyahu,

I am doing that. It is just that it is not able to read the values
back. To keep it simple, I am not changing selections either. I just
want the same values that were loaded. Somehow it can't read. It will
always give the first item in radiobuttonlist even though it is not
selected.

Thanks,

Raj

Eliyahu said:
You have to re-create dynamically created controls on every postback.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Raj said:
Hi there,

I am trying to get this work but I can't figure a solution. I have a
table on a web page (.aspx) and creating the table contents
dynamically. I have two cells for each row of table. First cell is a
label field, and second is a radiobuttonlist. Table looks some thing
like

Your favorite color? *)Red *)Blue *)Green
Age? *)20 *)30 *)40

Here comes the problem. In the submit button, I am trying to read the
selection as follows:

RadioButtonList rbl;
TableCell tc;
string sText;
int nTotal = tblStats.Rows.Count;
for (int i = 0; i < nTotal; i++)
{
tc = tblStats.Rows.Cells[1];
rbl = (RadioButtonList)tc.Controls[0];
sText = rbl.SelectedItem.Value;
}
The above code will always return the first selection (In the above
example: Red, 20 etc) Even if you select Blue, 40 etc. Actually that's
what the default selections were when page loads.
I have googled it but couldn't find what I was looking for. I will
truly appreciate your input.

Thank you,

Raj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top