473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DataList & Dynamic Controls

Hello,

I've got myself a small problem and I'm hoping someone can help.

I have a DataList called dlProducts (displays products from a database).
Within the <ItemTemplate> container of the DataList, I have a PlaceHolder
control called phVariations. During the ItemDataBound event for dlProducts,
I dynamically create a few DropDownLists (again, from a database) and .Add
the DropDownList to the PlaceHolder control. That all works just fine, my
drop downs show up, populated with data, everything looks good.

My problem comes from trying to access this data after postback. The
datalist is only bound when Page.IsPostBack = False and the dynamic controls
are created in the ItemDataBound event. I understand that viewstate only
captures the state of my dynamic controls and not the controls themselves. I
also know I have to recreate my controls during Page_Init or Page_Load and
they will then be repopulated by viewstate.

My question is that since the controls were created during ItemDataBound,
how am I going to recreate them for each Item in the DataList on postback
since the datalist is not bound then? I've been running into a brick wall
with this for a few hours now. Time to turn to others for assistance!

Thanks for anything you can contribute.

Scott

Nov 18 '05 #1
1 2653
Hi,

basically you should create the controls in ItemCreated so that they would
become created on every request in this case. ItemCreated happens despite is
it the initial request or postback and it happens before ItemDataBound.

And so if you create them based on data, you need to check in ItemCreated
(say by checking is e.Item.DataItem null or is DataList's DataSource null)
is it the databound recreate action or rehydrate/restoring action as it
happen on every request. If it is databound request, do the stuff in
ItemCreated as you now do, and on other case, just recreate the controls
(you might need to store counts etc into ViewState to be able to recreate
controls). Control state is then restored automatically after you get the
controls recreated.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"Scott Schluer" <us****@webservicesinc.biz> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello,

I've got myself a small problem and I'm hoping someone can help.

I have a DataList called dlProducts (displays products from a database).
Within the <ItemTemplate> container of the DataList, I have a PlaceHolder
control called phVariations. During the ItemDataBound event for dlProducts,
I dynamically create a few DropDownLists (again, from a database) and .Add
the DropDownList to the PlaceHolder control. That all works just fine, my
drop downs show up, populated with data, everything looks good.

My problem comes from trying to access this data after postback. The
datalist is only bound when Page.IsPostBack = False and the dynamic controls
are created in the ItemDataBound event. I understand that viewstate only
captures the state of my dynamic controls and not the controls themselves. I
also know I have to recreate my controls during Page_Init or Page_Load and
they will then be repopulated by viewstate.

My question is that since the controls were created during ItemDataBound,
how am I going to recreate them for each Item in the DataList on postback
since the datalist is not bound then? I've been running into a brick wall
with this for a few hours now. Time to turn to others for assistance!

Thanks for anything you can contribute.

Scott


Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Yan Wang | last post by:
Hi!: I encounter this problem when I do some tests: I have one user control with datalist in it. The ID for datalist is "dlTest". Then in this control code behind class, I declare a protected...
2
by: Patrick | last post by:
Hello I have a Datalist, that I fill with the PopulateList() method. This method selects all Items from Database and binds the Dataset to the DataLilst. Now, when clicking Edit, in the...
3
by: gowens | last post by:
I have an ASP.Net multi-part tabbed page. One of the tab pages contains several controls (including a DataList). The DataList contains, virtually-rendered, Database images and some text fields....
3
by: mbailey | last post by:
Hello- I am failry new to asp.net but have been coding in general for a while. I have a datalist whos templates are built on the fly. In the Page_Init sub, based on a certain value, certain...
0
by: KT | last post by:
Hi Everybody I'm hoping that someone can help me as I'm totally stumped. I am trying to populate a datalist using the dynamic templates. I have used the example on Microsofts site, I can't get...
3
by: Jon Paal | last post by:
how do I load controls to the templates for the DataList control. <asp:datalist id="dl1" runat="server" > <ItemTemplate> " how to load control(s) here ????" </ItemTemplate>...
0
by: Jim in Arizona | last post by:
Is there an easier way to make a datalist aware of line breaks within text fields? I have a text box that users can type into. If they press the enter key a few times, VB sees this as a vbCrLf....
4
by: .Net Sports | last post by:
I need to dynamically assign a datalist attribute upon a helper function receiving data from a querystring. If a user picks a certain region, i need the datalist to display its back color, or any...
0
by: =?Utf-8?B?Y2luZHk=?= | last post by:
I have am dynamically loading a web user control based on the click of a tab strip I load the default control for the first tab in the page load event after checking page is not postback. After...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.