PC Review


Reply
Thread Tools Rate Thread

Problem doing DataBind on a control within a DataList?

 
 
Olav Tollefsen
Guest
Posts: n/a
 
      29th Dec 2004
I have a Web Form with a DataList. Inside the ItemTemplate, I have a
DropDownList control.

<aspataList ID="ProductDataList" Runat="server">
<ItemTemplate>
<aspropDownList ID="DropDownList1" Runat="server"
DataTextField="PropertyValue" DataValueField="PropertyValueId">
</aspropDownList>
</ItemTemplate>
</aspataList>

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


 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      29th Dec 2004
Olav,

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

Eliyahu

"Olav Tollefsen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a Web Form with a DataList. Inside the ItemTemplate, I have a
> DropDownList control.
>
> <aspataList ID="ProductDataList" Runat="server">
> <ItemTemplate>
> <aspropDownList ID="DropDownList1" Runat="server"
> DataTextField="PropertyValue" DataValueField="PropertyValueId">
> </aspropDownList>
> </ItemTemplate>
> </aspataList>
>
> 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
>
>



 
Reply With Quote
 
 
 
 
Olav Tollefsen
Guest
Posts: n/a
 
      29th Dec 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Olav,
>
> It seems to me that you should be doing the databinding the dropdownlists
> in
> the datalist ItemDataBound event.
>
> Eliyahu
>
> "Olav Tollefsen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I have a Web Form with a DataList. Inside the ItemTemplate, I have a
>> DropDownList control.
>>
>> <aspataList ID="ProductDataList" Runat="server">
>> <ItemTemplate>
>> <aspropDownList ID="DropDownList1" Runat="server"
>> DataTextField="PropertyValue" DataValueField="PropertyValueId">
>> </aspropDownList>
>> </ItemTemplate>
>> </aspataList>
>>
>> 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
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to DataBind droplist control in FormView Control EditItem mode =?Utf-8?B?eXVjaGFuZw==?= Microsoft ASP .NET 0 15th Apr 2006 02:35 AM
Doing some extra task while saving databind Controls in VB.Net 2005 ? Luqman Microsoft VB .NET 4 30th Mar 2006 02:18 PM
How do i perform a databind on a web user control within a repeate =?Utf-8?B?bWlrZQ==?= Microsoft ASP .NET 0 16th May 2005 06:00 PM
How do i perform a databind on a web user control within a repeate =?Utf-8?B?bWlrZQ==?= Microsoft ADO .NET 0 16th May 2005 05:59 PM
What is Page.DataBind doing? For what is this useful? Andreas Klemt Microsoft ASP .NET 1 14th Jan 2004 02:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:20 AM.