Problem finding child control within nested DataList!

D

Doug

The html below shows DataList "DiscountList" nested within DataList
"EventItemList". DiscountList contains a Label control.

I'm trying to find the label, using FindControl, during
EventList_ItemCreated (below the html), but it's always <undefined
value> (null). Everything else works fine. Eventually I need to set
the value of the label depending up the Count of the DataView
"dvDiscount". For now I'll settle for just finding the damn thing!

Anyone got any ideas about this?
Thanks everyone.


<asp:DataList runat="server" Id="EventItemList" RepeatColumns="1">
<HeaderTemplate>
<span class="BookingItemShortDesc">
The following booking options are available:<br>
</span>
<br>
</HeaderTemplate>
<ItemTemplate>
<span class=TinyLabel>Qty&nbsp;<asp:TextBox runat="server"
columns=5 width=30px height=18px
CssClass="TinyLabel"></asp:TextBox>&nbsp;</span>
<span class="BookingItemTitle" style="MARGIN-LEFT:5px;">
&nbsp;<%# DataBinder.Eval(Container, "DataItem.Description") %>
</span>
<asp:DataList runat="server" Id="DiscountList" RepeatColumns="3">
<HeaderTemplate>
<asp:Label id="Label1" runat="server"></asp:Label>
<span class="BookingItemShortDesc" style="MARGIN-LEFT:45px;">
The following discounts are available:<br>
</span>
</HeaderTemplate>
<ItemTemplate>
<span class="BookingItemShortDesc" style="MARGIN-LEFT:50px">
<span class=TinyLabel>Qty</span>
<%# DataBinder.Eval(Container.DataItem, "BandLow") %>
<span class=TinyLabel>to</span>
<%# DataBinder.Eval(Container.DataItem, "BandHigh") %>
<span class=TinyLabel>=</span>
<%# DataBinder.Eval(Container.DataItem, "DiscountRate") %>
<span class=TinyLabel>%</span>
</span>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>


private void EventList_ItemCreated(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)
{

/************************** try to find the label *************/
Label lbl=((Label)e.Item.FindControl("Label1"));
if(lbl!=null)
lbl.Text="Label found";

if(e.Item.ItemType.ToString()=="Header")
{

}

if(e.Item.ItemType.ToString() == "Item" ||
e.Item.ItemType.ToString() ==
"AlternatingItem")
{
DataList dlTemp = ((DataList)e.Item.FindControl("DiscountList"));
int eventItemID = Convert.ToInt16(
((DataRowView)e.Item.DataItem).Row.ItemArray[0].ToString());

dvDiscount.RowFilter="EventItemID=" +
Convert.ToString(eventItemID);

if(dvDiscount.Count > 0)
{
DiscountHeading="The following discounts apply:";
//this.DiscountLabel.Text="Discounts";
}
else
{
DiscountHeading="";
//this.DiscountLabel.Text="";
}
dlTemp.DataSource = dvDiscount;//dvDiscount.RowFilter=
dlTemp.DataBind();
}
}
 
R

Rick Spiewak

Try finding the embedded datalist first, then the label within the selected
item in that datalist.
 

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

Members online

No members online now.

Forum statistics

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

Latest Threads

Top