468,249 Members | 1,490 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Problem finding child control within nested DataList!

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();
}
}
Nov 18 '05 #1
1 2881
Try finding the embedded datalist first, then the label within the selected
item in that datalist.

"Doug" <go**************@hotmail.com> wrote in message
news:a2**************************@posting.google.c om...
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();
}
}

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by CDWaddell | last post: by
1 post views Thread by Glenn Owens | last post: by
reply views Thread by nicklang | last post: by
5 posts views Thread by Jim in Arizona | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.