473,225 Members | 1,314 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,225 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 2643
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.