Problem doing DataBind on a control within a DataList?

O

Olav Tollefsen

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
 
E

Eliyahu Goldin

Olav,

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

Eliyahu
 
O

Olav Tollefsen

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 said:
Olav,

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

Eliyahu

Olav Tollefsen said:
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
 

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

Staff online

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top