unable do find dynamically created controls in a datalist

J

Jun

Hi
I am using a datalist control to display data from the database like everyone else. However I am unable to find dynamically created controls in the datalist.

Description
To simplify the use case, for every record I retrieve from the database, I display a checkbox, a hidden field containing the id of the current record, and a description of the record (Literal text). At the end of the datalist, I have a button that when clicked will call a server method that will loop thru the datalist and depending on the checkbox state, it does the appropriate database processing
When I physically design the UI in the ItemTemplate, everything works fine. I am able to loop thru the datalist items collection and within each datalistitem, I am able to do a FindControl and find the checkbox and hidden field

Problem
When I don't use the itemTemplate, but instead dynamically draw the checkbox, hidden button, and description in the datalist's ondatabind event, the method I call when I click the button is unable to find the checkbox nor the hidden button. The datalist draws fine. The result seems to be identical to the result I get when I physically design the UI. Everything works fine except for the method not being able to find the controls

did I miss something

Thanks

jun
 
A

Alvin Bruney [MVP]

Your post went unanswered. Have you resolved this issue?

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Jun said:
Hi,
I am using a datalist control to display data from the database like
everyone else. However I am unable to find dynamically created controls in
the datalist.
Description:
To simplify the use case, for every record I retrieve from the database, I
display a checkbox, a hidden field containing the id of the current record,
and a description of the record (Literal text). At the end of the datalist,
I have a button that when clicked will call a server method that will loop
thru the datalist and depending on the checkbox state, it does the
appropriate database processing.
When I physically design the UI in the ItemTemplate, everything works
fine. I am able to loop thru the datalist items collection and within each
datalistitem, I am able to do a FindControl and find the checkbox and hidden
field.
Problem:
When I don't use the itemTemplate, but instead dynamically draw the
checkbox, hidden button, and description in the datalist's ondatabind event,
the method I call when I click the button is unable to find the checkbox nor
the hidden button. The datalist draws fine. The result seems to be
identical to the result I get when I physically design the UI. Everything
works fine except for the method not being able to find the controls.
 

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

No members online now.

Forum statistics

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

Latest Threads

Top