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. Advertisements

  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. Advertisements

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:
    2,340
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,576
    David Schwartz
    Dec 9, 2003
  3. Replies:
    3
    Views:
    9,190
    Eliyahu Goldin
    Sep 17, 2006
  4. Ultrus
    Replies:
    3
    Views:
    612
    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:
    511
    Karthik Gurusamy
    Jan 26, 2008
  6. caldera

    Placeholder child of child control event problem.

    caldera, May 27, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    370
  7. SL

    DataList parrent control with a Repeater child control

    SL, Jun 24, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    247
  8. Will

    Problem with DataList within DataList

    Will, Oct 10, 2007, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    387
    Walter Wang [MSFT]
    Oct 18, 2007
Loading...