Problem finding child control within nested DataList!

Discussion in 'ASP .Net' started by Doug, Apr 20, 2004.

  1. Doug

    Doug Guest

    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();
    }
    }
     
    Doug, Apr 20, 2004
    #1
    1. Advertising

  2. Doug

    Rick Spiewak Guest

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

    "Doug" <> wrote in message
    news:...
    > 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();
    > }
    > }
     
    Rick Spiewak, Apr 22, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nevyn Twyll
    Replies:
    8
    Views:
    1,917
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,161
    David Schwartz
    Dec 9, 2003
  3. Replies:
    3
    Views:
    8,793
    Eliyahu Goldin
    Sep 17, 2006
  4. Ultrus
    Replies:
    3
    Views:
    390
    Stefan Behnel
    Jul 9, 2007
  5. Karthik Gurusamy

    finding child cpu usage of a running child

    Karthik Gurusamy, Jan 26, 2008, in forum: Python
    Replies:
    2
    Views:
    363
    Karthik Gurusamy
    Jan 26, 2008
Loading...

Share This Page