Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Problem finding child control within nested DataList!

Reply
Thread Tools

Problem finding child control within nested DataList!

 
 
Doug
Guest
Posts: n/a
 
      04-20-2004
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.


<aspataList 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>
<aspataList 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>
</aspataList>
</ItemTemplate>
</aspataList>


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();
}
}
 
Reply With Quote
 
 
 
 
Rick Spiewak
Guest
Posts: n/a
 
      04-22-2004
Try finding the embedded datalist first, then the label within the selected
item in that datalist.

"Doug" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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.
>
>
> <aspataList 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>
> <aspataList 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>
> </aspataList>
> </ItemTemplate>
> </aspataList>
>
>
> 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();
> }
> }



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
finding child cpu usage of a running child Karthik Gurusamy Python 2 01-26-2008 09:03 AM
dealing with nested xml within nested xml within...... Ultrus Python 3 07-09-2007 09:00 PM
Placeholder child of child control event problem. caldera ASP .Net Building Controls 1 05-28-2004 07:56 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM
Finding a Control within an <asp:table..> Control solveig Osk ASP .Net Web Controls 0 08-11-2003 02:08 PM



Advertisments