468,136 Members | 1,438 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,136 developers. It's quick & easy.

Problem doing DataBind on a control within a DataList?

I have a Web Form with a DataList. Inside the ItemTemplate, I have a
DropDownList control.

<asp:DataList ID="ProductDataList" Runat="server">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" Runat="server"
DataTextField="PropertyValue" DataValueField="PropertyValueId">
</asp:DropDownList>
</ItemTemplate>
</asp:DataList>

In the Page_Load for the Web Form, I do the following:

1) First I bind the DataList control to a data source.

ProductDataList.DataSource = product;
ProductDataList.DataBind();

2) Then I try to bind the DropDownList control to a data source:

DropDownList dropdown1 =
(DropDownList)ProductDataList.Items[0].FindControl("DropDownList1");
dropdown1.DataSource = propertyValues;
dropdown1.DataBind();

The code executes fine and I can see that the data source in step 2 is
containing the correct values that should be displayed in the DropDownList
control.

The problem is that the DropDownList control is empty. If I do exactly the
same with a DropDownList control that is placed on the Web Form outside the
DataList control, everything works just as expected.

Any hints on how to solve this problem?

Olav
Nov 19 '05 #1
2 1991
Olav,

It seems to me that you should be doing the databinding the dropdownlists in
the datalist ItemDataBound event.

Eliyahu

"Olav Tollefsen" <x@y.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
I have a Web Form with a DataList. Inside the ItemTemplate, I have a
DropDownList control.

<asp:DataList ID="ProductDataList" Runat="server">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" Runat="server"
DataTextField="PropertyValue" DataValueField="PropertyValueId">
</asp:DropDownList>
</ItemTemplate>
</asp:DataList>

In the Page_Load for the Web Form, I do the following:

1) First I bind the DataList control to a data source.

ProductDataList.DataSource = product;
ProductDataList.DataBind();

2) Then I try to bind the DropDownList control to a data source:

DropDownList dropdown1 =
(DropDownList)ProductDataList.Items[0].FindControl("DropDownList1");
dropdown1.DataSource = propertyValues;
dropdown1.DataBind();

The code executes fine and I can see that the data source in step 2 is
containing the correct values that should be displayed in the DropDownList
control.

The problem is that the DropDownList control is empty. If I do exactly the
same with a DropDownList control that is placed on the Web Form outside the DataList control, everything works just as expected.

Any hints on how to solve this problem?

Olav

Nov 19 '05 #2
Moving the code to the ItemDataBound event handler didn't make any
difference. Seems like the problem is related to using the Visual Studio
2005 Beta 1 refresh. I tested with Visual Studio 2004 and then it worked as
expected.

Olav

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:uQ**************@TK2MSFTNGP10.phx.gbl...
Olav,

It seems to me that you should be doing the databinding the dropdownlists
in
the datalist ItemDataBound event.

Eliyahu

"Olav Tollefsen" <x@y.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
I have a Web Form with a DataList. Inside the ItemTemplate, I have a
DropDownList control.

<asp:DataList ID="ProductDataList" Runat="server">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" Runat="server"
DataTextField="PropertyValue" DataValueField="PropertyValueId">
</asp:DropDownList>
</ItemTemplate>
</asp:DataList>

In the Page_Load for the Web Form, I do the following:

1) First I bind the DataList control to a data source.

ProductDataList.DataSource = product;
ProductDataList.DataBind();

2) Then I try to bind the DropDownList control to a data source:

DropDownList dropdown1 =
(DropDownList)ProductDataList.Items[0].FindControl("DropDownList1");
dropdown1.DataSource = propertyValues;
dropdown1.DataBind();

The code executes fine and I can see that the data source in step 2 is
containing the correct values that should be displayed in the
DropDownList
control.

The problem is that the DropDownList control is empty. If I do exactly
the
same with a DropDownList control that is placed on the Web Form outside

the
DataList control, everything works just as expected.

Any hints on how to solve this problem?

Olav


Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Lerp | last post: by
1 post views Thread by Craig | last post: by
3 posts views Thread by J'son | last post: by
1 post views Thread by yoknows | last post: by
reply views Thread by AleXmanFree | last post: by
reply views Thread by nicklang | last post: by
5 posts views Thread by Aussie Rules | last post: by
reply views Thread by Bieniu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.